Productify backend is a Node.js + Express server with a MongoDB Atlas database, providing RESTful API endpoints for managing products.
- Full CRUD API – Create, Read, Update, and Delete products.
- Advanced Filtering – Query products by name, type, and date range via query string parameters.
- Auto-increment
numberfield – Implemented via acounterscollection to ensure each product receives a unique running number, even after multiple insertions. - Seeding process –
npm run seedpopulates the database with initial products and updates the counter accordingly, ensuring the numbering remains continuous. - Error Handling – Consistent and descriptive API responses.
- Logger Middleware – Tracks incoming requests and errors.
- Node.js
- Express.js
- MongoDB Atlas
- dotenv for environment variables
- nodemon (development)
- Extract the project folder from the provided ZIP.
- Open a terminal inside the extracted folder.
- Install dependencies:
npm install
- Configure environment variables
Update.envwith your own connection details in place of<username>and<password>:ATLAS_URL=mongodb+srv://<username>:<password>@cluster0.mongodb.net/ ATLAS_DBNAME=product_db PORT=3030
- Seed the database (must be done before starting the server):
npm run seed
- Run the backend server:
API will be available at
npm start
http://localhost:3030/api/product.
productify-backend/
├── api/ # API route handlers
│ └── product/ # Product controller & routes
├── config/ # Config settings
├── middlewares/ # Logger and other middlewares
├── services/ # Database & product services
├── data/ # Seed data
├── .env # Environment variables
├── seed.js # Seed script
└── server.js # Entry point
Base URL: /api/product
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Get all products (with filters) |
| GET | /:id |
Get a single product by ID |
| POST | / |
Add a new product |
| PUT | /:id |
Update a product |
| DELETE | /:id |
Delete a product |
- Search term – Matches product name.
- Type filter –
vegetable,fruit, orfield. - Date range – Filters products by
marketingDate. - Query string sync – Filters are applied directly via URL parameters.
- Make sure to run the seed script before testing.
- The
numberfield auto-increments reliably even across multiple runs. - Do not commit
.envto source control.