Testing, Performance & Deployment
Node.js Deployment to Production
Deploying Node means running the app under a process manager behind a reverse proxy, with environment variables supplied by the platform, HTTPS terminated at the proxy, and logs collected centrally.
What is Deployment to Production in Node.js?
Deploying Node means running the app under a process manager behind a reverse proxy, with environment variables supplied by the platform, HTTPS terminated at the proxy, and logs collected centrally.
Deployment to Production example
server {
listen 443 ssl http2;
server_name api.example.com;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Key points to remember
- Set NODE_ENV=production — frameworks enable caching and skip development checks.
- Install with npm ci --omit=dev for a smaller, reproducible install.
- Terminate TLS at the proxy, not in Node.
- Set app.set("trust proxy", 1) so req.ip and rate limiting see the real client.
- Expose a /health endpoint for load balancer checks.
Common mistakes with Deployment to Production
- Running Node directly on port 443 as root.
- Leaving NODE_ENV unset, which keeps development behaviour and costs performance.
- Missing WebSocket upgrade headers, so Socket.IO silently falls back to polling.
Node.js Deployment to Production— Interview Questions & FAQs
Why use Nginx in front of Node?+
It terminates TLS, serves static files efficiently, handles compression and buffering, and shields the application from slow clients — all work Node would otherwise do less efficiently on its single thread.
