This is the backend service for the Reborne ecommerce application.
It is built using Node.js, Express, and MongoDB Atlas, and includes:
- Product CRUD APIs
- Order creation APIs
- User model with admin authentication (JWT-based)
- Seed script that inserts sample products and creates an admin account
- Ready for integration with any frontend (React, Next.js, etc.)
Copy .env.example → .env and fill in real values:
PORT=5000
MONGO_URI=your_mongo_connection_string_here
JWT_SECRET=your_jwt_secret_here
NODE_ENV=development
cd backend
npm installnpm run seedYou should see:
Data Imported
npm run devServer output should show:
MongoDB Connected: <your-host>
Server running in development mode on port 5000
Use this account to test admin endpoints:
email: admin@reborne.local
password: admin123
(Admin is created by the seed script.)
| Script | Description |
|---|---|
npm run dev |
Start dev server with nodemon |
npm run start |
Start server in production mode |
npm run seed |
Seed DB with sample products + admin |
POST /api/users/login
Body:
{
"email": "admin@reborne.local",
"password": "admin123"
}Response:
{
"_id": "...",
"name": "Admin",
"email": "admin@reborne.local",
"isAdmin": true,
"token": "<jwt_token_here>"
}| Method | Endpoint | Description |
|---|---|---|
| GET | /api/products |
Get all products |
| GET | /api/products/:id |
Get product by ID |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/products |
Create product |
| PUT | /api/products/:id |
Update product |
| DELETE | /api/products/:id |
Delete product |
Authorization header:
Authorization: Bearer <token>
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/orders |
Create order |
| GET | /api/orders/:id |
Get order details |
curl -X POST http://localhost:5000/api/users/login \
-H "Content-Type: application/json" \
-d '{"email":"admin@reborne.local","password":"admin123"}'curl http://localhost:5000/api/productscurl -X POST http://localhost:5000/api/products \
-H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-d '{"name":"Example","slug":"example","price":100,"countInStock":5}'http://localhost:5000
Add to frontend .env:
VITE_API_URL=http://localhost:5000
Example request:
fetch(`${import.meta.env.VITE_API_URL}/api/products`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${token}`
},
body: JSON.stringify({...})
});- Replace
JWT_SECRETwith a long random string. - Do NOT commit
.envto Git. - Commit
.env.exampleinstead. - Restrict CORS origin in production.
- Use Cloudinary/AWS S3 for image uploads.
- Add rate limiting to login endpoint.
- Validate inputs using express-validator or Joi.
- MongoDB models: Product, User, Order
- Controllers & Routes for products, orders, users
- JWT authentication
- Admin/Protect middleware
- Seed script (
npm run seed) - Clean folder structure