Can Node.js fully replace solutions like Apache or NGINX?

About deploying a Node.js application, I have seen a lot of tutorials showing it deployed side-by-side with Nginx, with more or less pretty tricks to allow the 2 to work together (and annoying stuff, like Nginx not supporting WebSockets). This seems a bit complicated to me ...

Why does everybody do this kind of setup ? Does deploying Nginx when you have Node.js provide any advantage ? Can't you serve static files with Node.js ?

I've written a lot of apps in Django, and the doc says that you shouldn't use Django to serve static files cause it's not optimized for this and so on ... so I was thinking maybe this is the reason.

Both Apache and NGINX are fully developed web servers offering lots of modules and services out of the box. They're considered robust and has proven stability for several years now.

Having that sort of available solutions, there's no need to re-invent the wheel. It can be more beneficial to implement the load balancer and routing with NGINX and not expose NodeJS to the outside and just run it on localhost.

NodeJS can't be considered a server software but merely a JavaScript framework. The fact that it's heavily used for server scripting does not make it web server.

If you decide to overlook the above and switch to NodeJS completely, i offer you think about maintaining such a solution. Logging, startup/shutdown scripts and monitoring can make the task more complicated than it seems.

Further more, numerous libraries written for NodeJS tend to break with new versions delivered, as breaking changes are introduced by NodeJS. Consider that as the price for the lack of maturity. If you're up to the risk and not afraid of problems, go for NodeJS.

Final note: static files can be served with NodeJS. Your scripts may read it and push it out.

Update: If you decided to go for Node.js consider to use Express.js framework.

Well some people don't mind using Node instead of nginx. Certain clouds like dotCloud or Nodejistu uses gateways entirely written in Node.js. Mostly to be able to handle websockets. But also because Node.js is damn fast.

Here is the gateway of dotCloud which has been open sourced recently https://github.com/dotcloud/hipache

I prefer using only node.js for the whole thing. The reason for that is, that many node applications have built-in file servers or depend on one that serves their files. So, every application can use the fileserver that fits best and can customize it to its needs.

Additionally, you lose a bit of performance when you have to proxy every single request from Apache/NGINX to node.js. It's much simpler to let node handle the requests by itself.