Skip to content

satyam-software-developer/ecommerce-api-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ E-Commerce REST API

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.


🌐 Live Demo

Live Application: https://e-com-api-r9km.onrender.com/


πŸš€ Features

  • πŸ” 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
  • 🧾 Logging

    • Request logging using file system

🧰 Tech Stack

  • Node.js
  • Express.js
  • MongoDB (Native Driver + Mongoose)
  • JWT (jsonwebtoken)
  • bcrypt
  • Multer (File uploads)
  • Swagger UI

πŸ“‚ Project Structure

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

βš™οΈ Environment Variables

Create a .env file in the root directory:

DB_URL=mongodb://localhost:27017/ecomdb
JWT_SECRET=your_jwt_secret

πŸ“¦ Installation & Setup

1️⃣ Clone the repository

git clone https://github.com/your-username/e-com-api.git
cd e-com-api

2️⃣ Install dependencies

npm install

3️⃣ Start the server

npm start

Server will start at:

http://localhost:3200

πŸ” Authentication Flow

  1. Signup β†’ /api/users/signup
  2. Signin β†’ /api/users/signin
  3. Receive JWT Token
  4. Pass token in headers:
Authorization: <JWT_TOKEN>

πŸ“˜ API Documentation

Swagger UI is available at:

http://localhost:3200/api-docs

Use the Authorize πŸ” button to add JWT token.


πŸ§ͺ Sample API Endpoints

πŸ”Ή Products

  • GET /api/products
  • POST /api/products (Protected)
  • POST /api/products/rate (Protected)
  • GET /api/products/filter
  • GET /api/products/averagePrice

πŸ”Ή Users

  • POST /api/users/signup
  • POST /api/users/signin
  • PUT /api/users/resetPassword (Protected)

πŸ”Ή Cart

  • POST /api/cartItems
  • GET /api/cartItems
  • DELETE /api/cartItems/:id

πŸ”Ή Orders

  • POST /api/orders (Protected)

πŸ”Ή Likes

  • POST /api/likes
  • GET /api/likes

πŸ›‘οΈ Error Handling

  • Centralized error handling middleware
  • Custom ApplicationError class
  • Mongoose validation error support

🧠 Learning Outcomes

This project demonstrates:

  • REST API design
  • MongoDB Aggregation Pipelines
  • Transactions with MongoDB Sessions
  • JWT Authentication
  • Clean architecture & modular code
  • Swagger API documentation

πŸ‘¨β€πŸ’» Author

Satyam Kumar Full Stack Software Engineer


⭐ Support

If you like this project, don’t forget to star ⭐ the repository and share it!

Happy Coding πŸš€

About

A scalable E-Commerce REST API built with Node.js, Express, MongoDB, and Mongoose, featuring JWT authentication, product & cart management, orders with transactions, likes, file uploads, logging, and Swagger API documentation.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors