A backend API for e-commerce platforms featuring product management, shopping cart, order processing, and image upload capabilities using Cloudinary.
- 🔐 Session-based authentication with bcrypt
- 📦 Product management with image upload
- 🛒 Shopping cart functionality
- 💳 Order management system
- 🖼️ Cloudinary integration for images
- ✅ Input validation
- Node.js - Runtime environment
- Express 5.1.0 - Web framework
- MongoDB - Database
- Mongoose 8.18.1 - ODM
- Cloudinary - Image hosting
- Multer - File upload handling
- bcrypt - Password hashing
- express-session - Session management
- express-validator - Input validation
-
Clone the repository
git clone https://github.com/javaadde/ecommerce_api.git cd ecommerce_api -
Install dependencies
npm install
-
Create
.envfilePORT=3000 MONGODB_URI=mongodb://localhost:27017/ecommerce_db SESSION_SECRET=your-session-secret CLOUDINARY_CLOUD_NAME=your_cloud_name CLOUDINARY_API_KEY=your_api_key CLOUDINARY_API_SECRET=your_api_secret
-
Run the application
node app.js
The API will be running at http://localhost:3000
POST /api/auth/register- Register new userPOST /api/auth/login- Login userPOST /api/auth/logout- Logout userGET /api/auth/me- Get current user
GET /api/products- Get all productsGET /api/products/:id- Get product by IDPOST /api/products- Create product (Admin)PUT /api/products/:id- Update product (Admin)DELETE /api/products/:id- Delete product (Admin)
GET /api/cart- Get user cartPOST /api/cart- Add item to cartPUT /api/cart/:itemId- Update cart itemDELETE /api/cart/:itemId- Remove item from cartDELETE /api/cart- Clear cart
GET /api/orders- Get user ordersGET /api/orders/:id- Get order by IDPOST /api/orders- Create new orderPUT /api/orders/:id/status- Update order status (Admin)
GET /api/users/profile- Get user profilePUT /api/users/profile- Update profilePUT /api/users/password- Change password
Register User
curl -X POST http://localhost:3000/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123",
"name": "John Doe"
}'Login
curl -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-c cookies.txt \
-d '{
"email": "user@example.com",
"password": "password123"
}'Get Products
curl -X GET http://localhost:3000/api/productsAdd to Cart
curl -X POST http://localhost:3000/api/cart \
-H "Content-Type: application/json" \
-b cookies.txt \
-d '{
"productId": "64abc123def456789",
"quantity": 2
}'Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the ISC License.
javaadde - GitHub
⭐ Star this repo if you find it helpful!