A simple and beginner-friendly Food Delivery Backend project built using Node.js, Express.js, and MongoDB Atlas.
You can easily run this project and test all APIs using Postman.
✅ Features:
- User Register & Login (JWT Token)
- Protected Profile Route
- Restaurant APIs (Add + List)
- Menu APIs (Add item + Get by restaurant)
- Orders APIs (Place order + My Orders)
- MongoDB relations + populate
- Node.js
- Express.js
- MongoDB Atlas (Mongoose)
- JWT Authentication
- bcryptjs
- Postman
git clone https://github.com/Sam103008/FOOD_DELIVERY_BACKEND.git
✅ Step 2: Install Dependencies
npm install
✅ Step 3: Create .env File (Important)
Project ke root folder me .env file banao:
📌 Path:
FOOD_DELIVERY_BACKEND/.env
Paste this inside .env:
PORT=5000
MONGO_URI=YOUR_MONGODB_ATLAS_URI
✅ Step 4: MongoDB Atlas Setup (Quick Steps)
MongoDB Atlas → Create Cluster
Database Access → Create user (username & password)
Network Access → Add IP → Allow 0.0.0.0/0 (testing)
Cluster → Connect → Drivers → Copy Mongo URI
✅ Example Mongo URI format:
MONGO_URI=<your_mongodb_uri_here>
⚠️ Note:
Password me @ ya special characters ho to error ho sakta hai
✅ Best: simple password use karo (example: sumit0000)
✅ Step 5: Start the Server
Development mode (recommended):
npm run dev
OR normal start:
npm start
✅ Expected output:
MongoDB Connected
Server running on port 5000
🧪 Postman Testing (Important)
✅ Base URL:
http://localhost:5000
✅ Protected APIs me token ka use hota hai:
Authorization: Bearer YOUR_TOKEN_HERE
📌 API Endpoints
✅ Auth APIs
Method Endpoint Description
POST /api/auth/register Register new user
POST /api/auth/login Login user + get JWT token
✅ User APIs (Protected)
Method Endpoint Description
GET /api/user/profile Get logged-in user profile
✅ Restaurant APIs
Method Endpoint Description
GET /api/restaurants Get all restaurants
POST /api/restaurants Add restaurant (Protected)
✅ Menu APIs
Method Endpoint Description
POST /api/menu Add menu item (Protected)
GET /api/menu/:restaurantId Get menu by restaurant
✅ Orders APIs (Protected)
Method Endpoint Description
POST /api/orders Place order
GET /api/orders/my Get my orders
✅ Example Requests (Postman)
✅ 1) Register User
POST /api/auth/register
URL:
http://localhost:5000/api/auth/register
Body (raw JSON):
{
"name": "__",
"email": "___@test.com",
"password": "10000"
}
✅ 2) Login User (Get Token)
POST /api/auth/login
URL:
http://localhost:5000/api/auth/login
Body:
{
"email": "__@test.com",
"password": "10000"
}
✅ Response:
{
"token": "YOUR_TOKEN_HERE"
}
✅ 3) Profile API (Protected)
GET /api/user/profile
URL:
http://localhost:5000/api/user/profile
Header:
Authorization: Bearer YOUR_TOKEN_HERE
✅ Response:
{
"message": "Profile route working ✅",
"userId": "..."
}
✅ 4) Add Restaurant (Protected)
POST /api/restaurants
URL:
http://localhost:5000/api/restaurants
Header:
Authorization: Bearer YOUR_TOKEN_HERE
Body:
{
"name": "____",
"address": "Nagpur",
"phone": "999999000",
"isOpen": true
}
✅ 5) Add Menu Item (Protected)
POST /api/menu
URL:
http://localhost:5000/api/menu
Header:
Authorization: Bearer YOUR_TOKEN_HERE
Body:
{
"restaurant": "RESTAURANT_ID_HERE",
"name": "Chicken Biryani",
"price": 250,
"category": "Biryani",
"isAvailable": true
}
✅ 6) Get Menu By Restaurant
GET /api/menu/:restaurantId
Example:
http://localhost:5000/api/menu/RESTAURANT_ID_HERE
✅ 7) Place Order (Protected)
POST /api/orders
URL:
http://localhost:5000/api/orders
Header:
Authorization: Bearer YOUR_TOKEN_HERE
Body:
{
"restaurant": "RESTAURANT_ID_HERE",
"items": [
{
"menuItem": "MENU_ITEM_ID_HERE",
"quantity": 2
}
]
}
✅ 8) Get My Orders (Protected)
GET /api/orders/my
URL:
http://localhost:5000/api/orders/my
Header:
Authorization: Bearer YOUR_TOKEN_HERE
✅ Response:
You will get your all orders list ✅
📁 Folder Structure
src/
┣ config/
┃ ┗ db.js
┣ controllers/
┣ middleware/
┣ models/
┣ routes/
┣ app.js
┗ server.js
✅ Project Progress (Day-wise)
✅ Day 1: Project Setup + Base Server
✅ Day 2: MongoDB + Auth APIs + JWT Middleware + Protected Route
✅ Day 3: Restaurants + Menu + Orders APIs
👤 Author
Amar
GitHub: https://github.com/Sam103008
⭐ If you like this project, give it a ⭐ on GitHub!
---
## ✅ README Push Commands
```bash
git add README.md
git commit -m "Add complete README documentation"
git push