A coffee ordering application built with Next.js (frontend) and Express (backend), optimized for Netlify serverless deployment.
- Node.js 18+
- MongoDB Atlas account
- Netlify account (for deployment)
-
Clone and Install
# Install backend dependencies cd backend npm install # Install frontend dependencies cd ../frontend npm install
-
Configure Environment
# Backend: Copy .env.example to .env cd backend cp .env.example .env # Edit .env and add your MongoDB connection string
-
Run Development Servers
# Terminal 1: Backend (Express server) cd backend npm run dev # Runs on http://localhost:5000 # Terminal 2: Frontend (Next.js) cd frontend npm run dev # Runs on http://localhost:3000
-
Access the App
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000/api/health
-
Push to GitHub
git add . git commit -m "Ready for Netlify deployment" git push origin main
-
Connect to Netlify
- Go to Netlify
- Click "Add new site" β "Import an existing project"
- Connect your Git repository
- Netlify auto-detects
netlify.tomlconfiguration
-
Configure Environment Variables
In Netlify Dashboard β Site settings β Environment variables:
Variable Value MONGODB_URIYour MongoDB Atlas connection string FRONTEND_URLYour Netlify site URL NODE_VERSION18 -
Deploy
- Click "Deploy site"
- Wait for build to complete
- Test your live site!
# Install Netlify CLI
npm install -g netlify-cli
# Login
netlify login
# Deploy
netlify deploy --prodCoffeeChaos/
βββ backend/
β βββ functions/
β β βββ api.js # Netlify serverless function
β βββ server.js # Express app (serverless-ready)
β βββ .env # Local environment variables
β βββ .env.example # Environment template
β βββ package.json
βββ frontend/
β βββ app/ # Next.js pages
β βββ components/ # React components
β βββ lib/
β β βββ axios.js # API client (auto-detects env)
β βββ next.config.js # Next.js config (static export)
β βββ package.json
βββ netlify.toml # Netlify deployment config
βββ DEPLOYMENT.md # Detailed deployment guide
βββ DEPLOYMENT_CHECKLIST.md # Step-by-step checklist
βββ CONVERSION_SUMMARY.md # Architecture overview
Configures Netlify build, functions, and redirects:
- Build command: Installs deps and builds frontend
- Publish directory:
frontend/out(static export) - Functions:
backend/functions - Redirects:
/api/*β serverless functions
Configures Next.js for static export:
output: 'export'- Generates static HTMLimages.unoptimized: true- Required for static export
Wraps Express app for Netlify Functions:
- Loads environment variables
- Uses
serverless-httpadapter - Handles all
/api/*routes
-
Create Cluster
- Sign up at MongoDB Atlas
- Create a free cluster
-
Create Database User
- Database Access β Add New Database User
- Set username and password
- Grant read/write permissions
-
Configure Network Access
- Network Access β Add IP Address
- For Netlify: Allow access from anywhere (
0.0.0.0/0)
-
Get Connection String
- Clusters β Connect β Connect your application
- Copy connection string
- Replace
<password>with your database password
The app automatically creates these collections:
users- User profiles and total cupsorders- Coffee ordersratings- Order ratings
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/health |
Health check |
| POST | /api/orders |
Create new order |
| GET | /api/orders/:username |
Get user's orders |
| GET | /api/leaderboard |
Get top 10 users by cups |
| POST | /api/ratings |
Submit order rating |
| GET | /api/ratings/:username |
Get user's ratings |
- β Coffee Ordering: Order different types of coffee
- π Leaderboard: See top coffee drinkers
- β Ratings: Rate your coffee orders
- π― Quiz: Coffee lover verification quiz
- π± Responsive: Works on all devices
- π Serverless: Scales automatically
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/database
PORT=5000 # Local dev only
FRONTEND_URL=http://localhost:3000 # Local devMONGODB_URI=mongodb+srv://... # Production database
FRONTEND_URL=https://your-site.netlify.app
NODE_VERSION=18# Test backend health
curl http://localhost:5000/api/health
# Test frontend
# Open http://localhost:3000 in browser# Test API
curl https://your-site.netlify.app/api/health
# Expected response:
# {"status":"OK","message":"Running!"}- DEPLOYMENT.md - Complete deployment guide with troubleshooting
- DEPLOYMENT_CHECKLIST.md - Step-by-step deployment checklist
- CONVERSION_SUMMARY.md - Architecture and conversion details
- Verify
MONGODB_URIis correct - Check MongoDB Atlas network access allows
0.0.0.0/0 - Verify database user credentials
- Check
netlify.tomlredirects - Verify
backend/functions/api.jsexists - Redeploy the site
- Update
FRONTEND_URLenvironment variable - Check CORS settings in
backend/server.js
See DEPLOYMENT.md for detailed troubleshooting.
- β Static HTML (pre-rendered)
- β CDN delivery via Netlify
- β Optimized assets
- β Serverless functions (auto-scaling)
- β MongoDB connection caching
- β Optimized pool size
- β MongoDB Atlas (managed)
- β Automatic backups
- β Global clusters
- Dashboard β Functions β View logs
- Dashboard β Analytics β Usage stats
- Metrics β Monitor connections
- Performance Advisor β Query optimization
- β Environment variables (not in code)
- β CORS configuration
- β MongoDB authentication
- β Network access controls
- β Deploy to Netlify
- β Test all features
- β Set up custom domain (optional)
- β Add database indexes for performance
- β Implement authentication (if needed)
- β Set up monitoring/alerts
ISC
Feel free to submit issues and pull requests!
Built with β€οΈ and β
For detailed deployment instructions, see DEPLOYMENT.md