A full-featured E‑Commerce REST API built using Node.js, Express, MongoDB, and Mongoose. This project demonstrates real‑world backend concepts such as authentication, authorization, transactions, aggregation pipelines, file uploads, logging, and API documentation with Swagger.
-
🔐 Authentication & Authorization
- JWT-based authentication
- Password hashing with bcrypt
- Protected routes using middleware
-
👤 User Management
- User signup & signin
- Password reset (JWT protected)
-
📦 Product Management
- Add products with image upload
- Fetch all products
- Filter products by price & category
- Rate products
- Average product price per category (Aggregation)
-
🛍️ Cart Management
- Add items to cart
- View cart items
- Remove items from cart
-
❤️ Like System
- Like Products or Categories
- Fetch likes with populated user & item
-
📑 Order Management
- Place orders using MongoDB transactions
- Stock reduction after order placement
- Cart auto-clear after order
-
📄 API Documentation
- Swagger UI available at
/api-docs
- Swagger UI available at
-
🧾 Logging
- Request logging using file system
- Node.js
- Express.js
- MongoDB (Native Driver + Mongoose)
- JWT (jsonwebtoken)
- bcrypt
- Multer (File uploads)
- Swagger UI
e-com-api/
│
├── src/
│ ├── config/
│ │ ├── mongodb.js
│ │ └── mongooseConfig.js
│ │
│ ├── features/
│ │ ├── user/
│ │ ├── product/
│ │ ├── cartItems/
│ │ ├── order/
│ │ └── like/
│ │
│ ├── middlewares/
│ │ ├── jwt.middleware.js
│ │ ├── logger.middleware.js
│ │ └── fileupload.middleware.js
│ │
│ └── error-handler/
│ └── applicationError.js
│
├── uploads/
├── swagger.json
├── server.js
├── .env
└── README.md
Create a .env file in the root directory:
DB_URL=mongodb://localhost:27017/ecomdb
JWT_SECRET=your_jwt_secret
git clone https://github.com/your-username/e-com-api.git
cd e-com-api
npm install
npm start
Server will start at:
http://localhost:3200
- Signup →
/api/users/signup - Signin →
/api/users/signin - Receive JWT Token
- Pass token in headers:
Authorization: <JWT_TOKEN>
Swagger UI is available at:
http://localhost:3200/api-docs
Use the Authorize 🔐 button to add JWT token.
GET /api/productsPOST /api/products(Protected)POST /api/products/rate(Protected)GET /api/products/filterGET /api/products/averagePrice
POST /api/users/signupPOST /api/users/signinPUT /api/users/resetPassword(Protected)
POST /api/cartItemsGET /api/cartItemsDELETE /api/cartItems/:id
POST /api/orders(Protected)
POST /api/likesGET /api/likes
- Centralized error handling middleware
- Custom
ApplicationErrorclass - Mongoose validation error support
This project demonstrates:
- REST API design
- MongoDB Aggregation Pipelines
- Transactions with MongoDB Sessions
- JWT Authentication
- Clean architecture & modular code
- Swagger API documentation
Satyam Kumar Full Stack Software Engineer
If you like this project, don’t forget to star ⭐ the repository and share it!
Happy Coding 🚀