A RESTful API for a food ordering application built with Node.js, Express, MongoDB, and Cloudinary for image uploads.
- JWT Authentication with HTTP-only cookies
- Role-based access (User, Restaurant Owner, Admin)
- Restaurant and menu management
- Shopping cart functionality
- Order management with status tracking
- Image uploads via Cloudinary
- Restaurant analytics and user order history
- Node.js + Express.js
- MongoDB + Mongoose
- JWT Authentication
- Cloudinary (Image uploads)
- bcryptjs (Password hashing)
-
Install dependencies
npm install
-
Environment Setup
Create
.envfile:PORT=5000 NODE_ENV=development MONGODB_URI=mongodb://localhost:27017/food_ordering_db JWT_SECRET=your_jwt_secret JWT_EXPIRE=7d JWT_COOKIE_EXPIRE=7 COOKIE_SECRET=your_cookie_secret CLOUDINARY_CLOUD_NAME=your_cloud_name CLOUDINARY_API_KEY=your_api_key CLOUDINARY_API_SECRET=your_api_secret
-
Start the server
npm run dev # Development npm start # Production
POST /api/auth/register- Register userPOST /api/auth/login- Login userPOST /api/auth/logout- Logout userGET /api/auth/me- Get current user
GET /api/restaurants- Get all restaurantsGET /api/restaurants/:id- Get single restaurantPOST /api/restaurants- Create restaurant (Restaurant role)
GET /api/foods- Get all foodsGET /api/foods/restaurant/my-dishes- Get restaurant's dishesPOST /api/foods- Add dish with images (Restaurant role)PUT /api/foods/:id- Update dishPATCH /api/foods/:id/price- Update price onlyDELETE /api/foods/:id- Delete dish
GET /api/cart- Get cartPOST /api/cart/add- Add to cartPUT /api/cart/update/:itemId- Update cart itemDELETE /api/cart/remove/:itemId- Remove from cart
POST /api/orders- Place orderGET /api/orders- Get user ordersGET /api/orders/history- Order history with statsGET /api/orders/restaurant/orders- Restaurant ordersGET /api/orders/restaurant/analytics- Restaurant analyticsPUT /api/orders/:id/status- Update order status
preparing→prepared→completedcancelled(only from preparing state)
- user - Browse and order food
- restaurant - Manage restaurant and menu
- admin - Full system access
├── server.js
├── package.json
├── .env
└── src/
├── app.js
├── config/
├── controllers/
├── middleware/
├── models/
└── routes/
npm start # Start production server
npm run dev # Start development serverISC