An open API service indexing awesome lists of open source software.

https://github.com/tarushbatra/inventory-api

Inventory Management System API built with Node.js, Express, and MongoDB. Includes CRUD operations, stock management, and Jest tests.
https://github.com/tarushbatra/inventory-api

express jest mongodb nodejs rest-api

Last synced: 3 months ago
JSON representation

Inventory Management System API built with Node.js, Express, and MongoDB. Includes CRUD operations, stock management, and Jest tests.

Awesome Lists containing this project

README

          

# ๐Ÿ“ฆ Inventory Management API

[![Node.js](https://img.shields.io/badge/Node.js-18.x-green.svg)](https://nodejs.org/)
[![Express](https://img.shields.io/badge/Express-4.x-lightgrey.svg)](https://expressjs.com/)
[![MongoDB](https://img.shields.io/badge/MongoDB-6.x-brightgreen.svg)](https://www.mongodb.com/)
[![Jest](https://img.shields.io/badge/Tests-Passing-brightgreen.svg)](https://jestjs.io/)

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.

---

## ๐Ÿš€ Features
- 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

---

## ๐Ÿ“‚ Project Structure
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

---

## โš™๏ธ Setup & Installation

### 1. Clone the repo
``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.