Backend service for the CoolGarmi E-Commerce platform, providing API endpoints for products, users, orders, and more.
These instructions will help you set up and run the project on your local machine for development and testing purposes.
- Node.js (v14 or higher)
- MongoDB
- npm or yarn
-
Clone the repository
git clone <repository-url> cd E-Commerce-Backend -
Install dependencies
npm install -
Set up environment variables Create a
.envfile in the root directory and add the following variables:MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret_key PORT=5000
To run the application in development mode with nodemon (auto-restart on file changes):
npm run dev
To populate the database with sample data (products, users, orders):
npm run seed
After running the seed script, you can use these credentials to login with different roles:
- Email: admin@coolgarmi.com
- Password: admin123
-
Email: rider1@coolgarmi.com
-
Password: rider123
-
Email: rider2@coolgarmi.com
-
Password: rider123
Note: These credentials will only work after successfully seeding the database.
The frontend of this application is available at: E-Commerce Frontend
POST /api/auth/register- Register a new userPOST /api/auth/login- Login a userGET /api/auth/me- Get current user details
GET /api/products- Get all productsGET /api/products/:id- Get product by IDPOST /api/products- Create a new product (Admin only)PUT /api/products/:id- Update a product (Admin only)DELETE /api/products/:id- Delete a product (Admin only)
GET /api/orders- Get all orders (Admin only)GET /api/orders/my-orders- Get current user's ordersPOST /api/orders- Create a new orderPUT /api/orders/:id/status- Update order status (Admin/Rider only)
E-Commerce-Backend/
├── models/ # MongoDB schema models
├── controllers/ # Route controllers
├── routes/ # API routes
├── middleware/ # Custom middleware
├── utils/ # Utility functions
├── config/ # Configuration files
└── server.js # Entry point
- Node.js & Express - Server framework
- MongoDB & Mongoose - Database
- JSON Web Token (JWT) - Authentication
- bcryptjs - Password hashing