Why do we need apache under Node.js express web framework? Why do we need apache under Node.js express web framework? express express

Why do we need apache under Node.js express web framework?


Putting Apache in front of Node is not typical in a greenfield app. The only case I can grant to this is if your company has an existing investment in an Apache based infrastructure (monitoring/security/routing/caching etc..) on the frontend and the sysadmin insist on this setup.

Some folks prefer to put nginx or haproxy in front to manage routing rules, so they can channel requests for static files (assets) away from Node.js (node.js wasn't always performant when handling static files), or do fancy load balancing or failover. In the early days of 0.2.x etc... even Ryan Dahl advocated running something in front of Node.js for security mainly; although, I don't think any significant issues were discovered. I personally run nginx in front of Node.js as we have several sites and services that hit the frontend shared IP which we proxy back to various node instances listening on different internal ports.

Nginx is better suited than Apache as it is light and single threaded vs Apache thread per request (in most normal setups). But nowadays there's even a reliable (node-http-proxy excluded) frontend Node.JS based proxy http://www.github.com/substack/bouncy which one of the celebrity node.js developers uses/will-use to frontend his PaaS.


First of all, yes use nginx not Apache - it's far easier to configure nginx, and it's lighter and more efficient.

With an nginx proxy up front you get several advantages:

  • Ability to run several backends for different parts of your site
  • A faster static file server
  • Clean restarts if you need to take down your Node server (nginx can deliver a pretty "under maintenance" page)
  • Logging in your node app can focus on debugging, and nginx can log requests - keeps it nice and clean

And probably other things I've missed.

Once really nice thing nginx can do is the "try_files" directive, which will look for local files first, and if it doesn't find them it passes off to the Node backend.


Reasons for using an webserver like apache or in most cases nginx are:

  1. Load Balancing - It is very common practise to use web-server in front of a application/web server for load balancing
  2. Caching - Webserver like nginx provide extensive caching abilities compared to that of nodejs or other such application servers
  3. Request handling - Pure webserver like nginx is far superior in terms of handling multiple request at a time i.e high concurrency.

Caching and Superior Request handling abilities of webserver like nginx make them a killer choice to be used as proxy servers in front of nodejs easing off load from them.

Also of serving static files using webservers are very common instead of nodejs due to above mentioned reasons.