A fully functional E-commerce Backend API built using Node.js, Express, and MongoDB. This project includes authentication, role-based access, product management, cart, orders, wishlist, and user profile.
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT Authentication
- bcrypt (password hashing)
- Helmet (security)
ecommerce-api/
│── config/
│── middleware/
│── models/
│── routes/
│── validators/
│── server.js
│── .env
│── package.json
- User Signup
- User Login (JWT based)
- Role-based access (User / Admin)
- Create Product (Admin)
- Get All Products
- Get Product Details
- Update Product (Admin)
- Delete Product (Admin)
- Add to Cart
- Get Cart
- Update Quantity
- Remove Item
- Clear Cart
- Create Order (Checkout)
- Get My Orders
- Get Order Details
- Admin: Get All Orders
- Admin: Update Order Status
- Add to Wishlist
- Get Wishlist
- Remove Item
- Clear Wishlist
- Get Profile
- Update Profile
- Change Password
Create a .env file in root:
MONGO_URI=mongodb://127.0.0.1:27017/ecommerce
JWT_SECRET=your_secret_key
git clone https://github.com/YOUR_USERNAME/ecommerce-api.git
cd ecommerce-api
npm install
npm run dev
Server will run on:
http://localhost:5000
All protected routes require JWT token in headers:
Authorization: Bearer <your_token>
POST /api/auth/signup
POST /api/auth/login
GET /api/products
GET /api/products/:id
POST /api/products (Admin)
PUT /api/products/:id (Admin)
DELETE /api/products/:id (Admin)
POST /api/cart/add
GET /api/cart
PUT /api/cart/update
DELETE /api/cart/remove/:id
DELETE /api/cart/clear
POST /api/orders/create
GET /api/orders/my
GET /api/orders/:id
GET /api/orders (Admin)
PUT /api/orders/:id (Admin)
POST /api/wishlist/add
GET /api/wishlist
DELETE /api/wishlist/remove/:id
DELETE /api/wishlist/clear
GET /api/user/profile
PUT /api/user/profile
PUT /api/user/password
User → Signup/Login → JWT Token
↓
Browse Products
↓
Add to Cart
↓
Create Order (Checkout)
↓
Admin manages products & orders
- Password hashing using bcrypt
- JWT authentication
- Helmet for HTTP security headers
Meet Vora
If you like this project, give it a ⭐ on GitHub!