A simple Inventory Management System API built with Node.js, Express, and MongoDB.
It allows you to manage products, update stock, enforce business rules (no negative stock), and check for low stock thresholds.
- Product CRUD (Create, Read, Update, Delete)
- Stock management (increase / decrease stock with validation)
- Low stock check
- Prevent stock from going below zero
- Jest + Supertest for testing
- Postman Collection included for quick testing
inventory-api/ βββ src/ β βββ config/ # Database connection β βββ controllers/ # Request handlers β βββ models/ # Mongoose models β βββ routes/ # API routes β βββ services/ # Business logic β βββ utils/ # Error handling β βββ app.js # Express app β βββ server.js # Server entrypoint βββ tests/ # Jest + Supertest test cases βββ .gitignore βββ package.json βββ README.md βββ Inventory API.postman_collection.json
``bash git clone https://github.com/TarushBatra/inventory-api.git cd inventory-api 2. Install dependencies npm install 3. Setup environment variables
Create a .env file in root: PORT=5000 MONGO_URI=mongodb://localhost:27017/inventoryDB 4. Start development server npm run dev Server runs at π http://localhost:5000
π‘ API Endpoints Products Method Endpoint Description GET /api/products Get all products GET /api/products/:id Get product by ID POST /api/products Create a new product PUT /api/products/:id Update product details DELETE /api/products/:id Delete product PATCH /api/products/:id/increase Increase stock PATCH /api/products/:id/decrease Decrease stock GET /api/products/low-stock Get low stock products π§ͺ Running Tests
Run Jest + Supertest tests: npm test
β Tests include:
Create product
Increase stock
Decrease stock
Prevent negative stock
Low stock check
π¬ Postman Collection
File: Inventory API.postman_collection.json
To use:
Open Postman
Go to Collections β Import
Select this file
Run sample requests for all endpoints
π¨βπ» Tech Stack
Node.js
Express.js
MongoDB + Mongoose
Jest + Supertest
π License
This project is licensed under the MIT License.