Mock Express server for food ordering interview problem. Uses data.json for persistence without a database.
npm install# Development (with auto-reload)
npm run dev
# Production
npm startServer runs on http://localhost:3001
- ✅ Menu items with branch-specific availability
- ✅ Multiple branch support
- ✅ Real-time availability changes (auto-polling simulation)
- ✅ Simple, clean API with only 2 endpoints
- ✅ CORS enabled for frontend integration
GET /api/branches
Response:
{
"success": true,
"data": [
{
"id": "branch_1",
"name": "Downtown Branch",
"address": "123 Main St"
},
{
"id": "branch_2",
"name": "Uptown Branch",
"address": "456 Park Ave"
}
],
"timestamp": 1234567890
}GET /api/branches/:branchId/menu
Parameters:
branchId(path parameter): The ID of the branch (e.g., "branch_1")
Response:
{
"success": true,
"data": [
{
"id": "item_1",
"name": "Margherita Pizza",
"description": "Classic tomato and mozzarella",
"price": 12.99,
"category": "Pizza",
"image": "https://via.placeholder.com/150",
"isAvailable": true
},
{
"id": "item_2",
"name": "Pepperoni Pizza",
"description": "Pepperoni and cheese",
"price": 14.99,
"category": "Pizza",
"image": "https://via.placeholder.com/150",
"isAvailable": true
}
],
"timestamp": 1234567890
}Error Response (Branch not found):
{
"success": false,
"message": "Branch not found"
}The server automatically changes item availability every 10 seconds to simulate real-world scenarios.
Frontend polling example:
// Poll menu every 5 seconds for a specific branch
const branchId = 'branch_1';
setInterval(async () => {
const response = await fetch(`http://localhost:3001/api/branches/${branchId}/menu`);
const data = await response.json();
// Update your state with new data
// Check data.timestamp to see when data was fetched
}, 5000);# Get all branches
curl http://localhost:3001/api/branches
# Get menu for branch_1
curl http://localhost:3001/api/branches/branch_1/menu
# Get menu for branch_2
curl http://localhost:3001/api/branches/branch_2/menu
# Try invalid branch (should return 404)
curl http://localhost:3001/api/branches/invalid_branch/menu- All timestamps are in milliseconds (Unix epoch)
- Data persists in
data.jsonacross server restarts - CORS is enabled for all origins (adjust for production)