A full-stack pharmacy inventory app:
- Backend: Node.js + Express + MongoDB
- Frontend: React (Vite or CRA)
- CORS , AXIOS , Mongoose , TailwindCSS
- Full CRUD via custom APIs
- Total 6 API endpoints across the single page and form
- Track low-stock and expired medicines
- Live deployments:
- Backend: Render
- Frontend: Vercel
-
cd pharmacy-backend -
npm install -
Create
.env:
MONGO\_URI=your\_mongodb\_connection\_string
- Optional: include
PORT=8080, or let default in code handle it
- Start:
npm start(production) ornpm run dev(with nodemon) - API Base URL:
http://localhost:8080/api/medicines
| Method | URL | Description |
|---|---|---|
| GET | /api/medicines |
List all medicines |
| GET | /api/medicines/low-stock |
Items with quantity < 10 |
| GET | /api/medicines/expired |
Expired medicines |
| POST | /api/medicines |
Create new medicine |
| PUT | /api/medicines/:id |
Update medicine by ID |
| DELETE | /api/medicines/:id |
Delete medicine by ID |
[
{
"_id": "64abbc12345fgh67890jk12",
"name": "Paracetamol",
"brand": "Panadol",
"batchNumber": "B12345",
"quantity": 100,
"price": 12.5,
"expiryDate": "2026-12-31T00:00:00.000Z",
"category": "Painkiller"
}
]-
Push repo to GitHub
-
In Render:
- Create New Web Service
- Root:
pharmacy-backend - Start:
npm start - Add env var
MONGO_URI(value from.env)
-
Render deploys → copy the service URL (e.g.
https://pharmacy-backend.onrender.com)
Ensure your API path works via:
https://pharmacy-backend.onrender.com/api/medicines
-
cd pharmacy-frontend -
npm install -
Create
.env:VITE_BACKEND_URL=http://localhost:8080/api/medicines -
Run locally:
npm run dev -
Access in browser:
http://localhost:3000
-
Connect GitHub repo
-
Configure project:
-
Root directory:
pharmacy-frontend -
Build:
npm run build -
Output folder:
build(CRA) ordist(Vite) -
Env var:
-
I have used hardcoded url , u can do the following :
VITE_BACKEND_URL=https://<your-render-backend>/api/medicines
-
-
Deploy & access live URL
- Test individual controller logic (e.g.,
medicineController.js) - Mocked dependencies with
vi.mock()to isolate business logic
- Use
mongodb-memory-serverfor in-memory MongoDB - Test Mongoose models with real-like DB operations
- Use
supertestto test API endpoints - Validate full request-response cycle
| Tool | Purpose |
|---|---|
vitest |
Test runner, assertions, mocking |
supertest |
HTTP assertions |
mongodb-memory-server |
Ephemeral MongoDB (in-memory) |
@vitest/coverage-v8 |
HTML + CLI coverage reports |
From the pharmacy-backend directory:
npm testTo view code coverage:
npm run coverageThen open the report:
pharmacy-backend/coverage/index.html
- Enter item in form
- Request sent via API to backend
- Backend acts (DB operation, returns data)
- Frontend UI updates accordingly
- Buttons available for filtering by stock or expiry status , expired products highlighted in red and low stocks in yellow
- Fork the repo
git checkout -b feature/<your-feature>- Commit:
git commit -am "Feature x added" - Push & Open PR
