A RESTful API for an e-commerce platform built with Node.js, Express, and MongoDB. This backend API powers a complete e-commerce platform with user authentication, product management, shopping cart, order processing, and integrated payment system.
- ๐ JWT Authentication - Secure user registration and login
- ๐ค User Management - Profile updates, password change, OTP-based password reset
- ๐ฆ Product Catalog - CRUD operations with search and category filtering
- ๐ผ๏ธ Image Upload - Multi-image support via Cloudinary
- ๐ Shopping Cart - Add, update, remove items
- ๐ณ Payment Integration - Stripe payment gateway
- ๐ Order Management - Complete order lifecycle tracking
- ๐ง Admin Panel - Product, category, and order management
- ๐ง Email Service - OTP verification via Nodemailer
- ๐ก๏ธ Security - Password hashing, secure cookies, CORS
| Category | Technologies |
|---|---|
| ๐ Backend |
|
| ๐๏ธ Database |
|
| ๐ Authentication |
|
| ๐ณ Payment |
|
| โ๏ธ Cloud & File Handling |
|
| ๐ง Communication |
|
| ๐ก๏ธ Security & Middleware |
|
| โ Validation |
|
โโโ controllers/ # Business logic
โ โโโ user.js # Authentication & user management
โ โโโ product.js # Product & category operations
โ โโโ order.js # Order processing
โโโ models/ # MongoDB schemas
โ โโโ user.js
โ โโโ product.js
โ โโโ order.js
โ โโโ category.js
โโโ routes/ # API endpoints
โ โโโ user.js
โ โโโ product.js
โ โโโ order.js
โโโ middlewares/ # Custom middleware
โ โโโ auth.js # Authentication & authorization
โ โโโ error.js # Error handling
โ โโโ multer.js # File upload
โโโ utils/ # Helper functions
โ โโโ features.js # Utility functions
โ โโโ error.js # Custom error class
โโโ data/
โ โโโ database.js # MongoDB connection
โโโ postman/ # API testing
โ โโโ Ecommerce-Backend.postman_collection.json
โ โโโ POSTMAN-SETUP.md # Postman setup guide
โโโ .env # Environment variables
โโโ app.js # Express configuration
โโโ README.md # Project documentation
โโโ package.json # Dependencies
- Node.js (v14+)
- MongoDB
- Cloudinary account
- Stripe account
- Clone the repository
git clone <repository-url>
cd ecommerce-backend- Install dependencies
npm install- Configure environment variables
Create data/config.env:
PORT=5000
NODE_ENV=Development
MONGO_URI=your_mongodb_uri
JWT_SECRET=your_jwt_secret
CLOUDINARY_NAME=your_cloudinary_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
STRIPE_API_SECRET=your_stripe_secret
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_USER=your_email@gmail.com
SMTP_PASS=your_email_password
FRONTEND_URI_1=http://localhost:3000
FRONTEND_URI_2=http://localhost:5173- Run the server
npm run devServer runs on http://localhost:4000
We provide a complete Postman collection for easy API testing and integration.
- Import the collection into Postman from postman/Ecommerce-Backend.postman_collection.json
- Set up environment variables (BASE_URL, ACCESS_TOKEN)
- Start testing all endpoints!
๐ View Complete Postman Setup Guide POSTMAN-SETUP.md
POST /api/v1/user/new # Register
POST /api/v1/user/login # Login
GET /api/v1/user/logout # Logout
GET /api/v1/user/me # Get profile
PUT /api/v1/user/updateprofile # Update profile
PUT /api/v1/user/changepassword # Change password
PUT /api/v1/user/updatepic # Update avatar
POST /api/v1/user/forgetpassword # Request OTP
PUT /api/v1/user/resetpassword # Reset with OTP
GET /api/v1/product/all # Get all products
GET /api/v1/product/admin # Admin dashboard
GET /api/v1/product/single/:id # Get single product
POST /api/v1/product/new # Create product (Admin)
PUT /api/v1/product/single/:id # Update product (Admin)
POST /api/v1/product/images/:id # Add image (Admin)
DELETE /api/v1/product/images/:id # Delete image (Admin)
DELETE /api/v1/product/single/:id # Delete product (Admin)
GET /api/v1/product/categories # Get all categories
POST /api/v1/product/category # Add category (Admin)
DELETE /api/v1/product/category/:id # Delete category (Admin)
POST /api/v1/order/payment # Create payment intent
POST /api/v1/order/new # Place order
GET /api/v1/order/my # Get my orders
GET /api/v1/order/single/:id # Get order details
GET /api/v1/order/admin # Get all orders (Admin)
PUT /api/v1/order/single/:id # Process order (Admin)
- Email, password (hashed), name, address details
- Avatar with Cloudinary integration
- Role-based access (user/admin)
- OTP for password reset
- Name, description, price, stock
- Multiple images (Cloudinary)
- Category reference
- Timestamps
- Shipping information
- Order items with product references
- Payment details (COD/Online)
- Status tracking (Preparing โ Shipped โ Delivered)
- Automatic stock updates
- Simple category name
- โ JWT-based authentication
- โ Password hashing with bcrypt (10 rounds)
- โ HTTP-only secure cookies
- โ CORS configuration
- โ Input validation
- โ OTP-based password reset
- โ Protected routes with middleware
- โ Admin authorization checks
This project demonstrates:
- RESTful API design principles
- Authentication and authorization
- Database modeling with relationships
- Payment gateway integration
- Cloud storage implementation
- Email service integration
- Error handling best practices
- Middleware architecture
- Secure coding practices
The project uses separate environment configurations:
Development- Local testing with detailed errorsProduction- Optimized for deployment
Use tools like Postman, Thunder Client, or cURL:
# Test server status
curl http://localhost:5000/
# Register user
curl -X POST http://localhost:5000/api/v1/user/new \
-H "Content-Type: application/json" \
-d '{"name":"John","email":"john@example.com","password":"123456"}'- Environment-based configuration
- MongoDB Atlas compatible
- Cloudinary cloud storage
- Stripe production keys support
- CORS configured for frontend
- Ready for Heroku, Railway, Render, etc.
- Mongoose query optimization
- Efficient image storage with Cloudinary
- Proper indexing on database
- Async/await for non-blocking operations
- Error handling prevents crashes
Success Response:
{
"success": true,
"message": "Operation successful",
"data": {}
}Error Response:
{
"success": false,
"message": "Error description"
}{
"express": "^4.18.2",
"mongoose": "^6.7.2",
"jsonwebtoken": "^8.5.1",
"bcrypt": "^5.1.0",
"cloudinary": "^1.32.0",
"stripe": "^10.17.0",
"nodemailer": "^6.8.0",
"multer": "^1.4.5-lts.1",
"validator": "^13.7.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.0.3"
}- Product reviews and ratings
- Advanced search with filters
- Pagination for large datasets
- Admin analytics dashboard
- Real-time notifications
- Order cancellation and refunds
- Coupon/discount system
- Product recommendations
โญ If you found this project helpful, please consider giving it a star!