Backend & APIs / Server-Restaurant
Restaurant Backend Server
A modern restaurant management server with authentication and API endpoints built with Node.js, Express, and MongoDB.
Open the full technical write-up
A modern restaurant management server with authentication and API endpoints built with Node.js, Express, and MongoDB.
Quick Start
Prerequisites
- Node.js >= 14.0.0
- MongoDB (local or Atlas)
Installation
- Clone and install dependencies:
git clone
cd Server-Restaurant
npm install
- Set up environment variables:
cp env.example .env
# Edit .env with your configuration
- Start development server:
npm run dev
Configuration
Environment Variables
Copy env.example to .env and configure:
# Server Configuration
NODE_ENV=development
PORT=8000
# Database Configuration
MONGO_URL=mongodb://127.0.0.1:27017/conFusion
# Security
SECRET_KEY=your-super-secret-key-here
JWT_SECRET=your-jwt-secret-key-here
# CORS Configuration
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:4200,http://localhost:8000
Database Management
Initial Setup
Populate the database with sample data:
npm run populate
Database Operations
# Backup database
npm run db:backup
# Restore from backup
npm run db:restore ./backups/backup-2024-01-01.json
# Clear database
npm run db:clear
# View database statistics
npm run db:stats
# Run database migrations
npm run db:migrate
Manual Database Management
# Backup specific collection
node scripts/db-manager.js backup dishes
# Clear specific collection
node scripts/db-manager.js clear users
# View all commands
node scripts/db-manager.js
How files are organized
Server-Restaurant/
├── app.js # Express app configuration
├── config.js # Configuration management
├── populateDb.js # Database population script
├── db.json # Sample data
├── scripts/
│ └── db-manager.js # Database management
├── models/ # MongoDB models
├── routes/ # API routes
├── public/ # Static files
├── sessions/ # Session storage
└── backups/ # Database backups
API Endpoints
Authentication
POST /users/signup- User registrationPOST /users/login- User loginGET /users/logout- User logout
Dishes
GET /dishes- Get all dishesGET /dishes/:id- Get specific dishPOST /dishes- Create new dish (admin)PUT /dishes/:id- Update dish (admin)DELETE /dishes/:id- Delete dish (admin)
Leaders
GET /leaders- Get all leadersGET /leaders/:id- Get specific leaderPOST /leaders- Create new leader (admin)PUT /leaders/:id- Update leader (admin)DELETE /leaders/:id- Delete leader (admin)
Promotions
GET /promotions- Get all promotionsGET /promotions/:id- Get specific promotionPOST /promotions- Create new promotion (admin)PUT /promotions/:id- Update promotion (admin)DELETE /promotions/:id- Delete promotion (admin)
Comments & Feedback
GET /comments- Get all commentsPOST /comments- Add commentGET /feedback- Get all feedbackPOST /feedback- Submit feedback
Favorites
GET /favorites- Get user favoritesPOST /favorites/:dishId- Add to favoritesDELETE /favorites/:dishId- Remove from favorites
File Upload
POST /imageUpload- Upload images
Security Features
- JWT authentication
- Session management
- CORS protection
- Input validation
- XSS protection
- CSRF protection
- Secure headers
Monitoring & Maintenance
Health Check
curl http://localhost:8000/
Database Monitoring
# Check database statistics
npm run db:stats
# Monitor database size
node scripts/db-manager.js stats
Backup Strategy
# Daily backup (add to cron)
0 2 * * * cd /path/to/server && npm run db:backup
# Manual backup before updates
npm run db:backup
Troubleshooting
Common Issues
-
Database Connection Issues:
- Check MONGO_URL in environment variables
- Ensure MongoDB is running
- Verify network connectivity
-
Port Already in Use:
- Check if another process is using the port
- Change PORT in environment variables
- Kill existing processes:
lsof -ti:8000 | xargs kill
Logs
- Application logs: Check console output
- Session logs:
./sessions/ - Database logs: MongoDB logs
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Support
For issues and questions:
- Check the troubleshooting section
- Review the API documentation
- Create an issue in the repository