What is the role of reverse proxies in Express.js production deployments?
Answer
In production, Express typically runs behind a reverse proxy (Nginx, Apache, or a load balancer). The proxy handles: SSL termination (manages HTTPS, Express only sees HTTP internally). Static file serving (far more efficient than Express static middleware). Load balancing across multiple Node.js instances. Compression (gzip at proxy level). Connection limiting and request buffering. Configure Express to trust the proxy's forwarded headers: app.set('trust proxy', 1) — this ensures req.ip returns the client's real IP (not the proxy's) and req.secure correctly reflects HTTPS. Without this setting, rate limiting by IP and HTTPS redirects break behind a proxy.
Previous
What is the Express.js application lifecycle?
Next
How do you prevent SQL injection in an Express.js application?
More Express.js Questions
View all →- Advanced How do you implement WebSocket support alongside Express.js?
- Advanced What are security best practices for Express.js APIs?
- Advanced How does clustering work in Node.js/Express for better performance?
- Advanced What is the difference between Express 4.x and Express 5.x?
- Advanced How do you implement a graceful shutdown in Express.js?