Why is it not recommended to serve static files from Node.js?

View other answers to this thread
Start a personal dev blog on your domain for free and grow your readership.

3.4K+ developers have started their personal blogs on Hashnode in the last one month.

Write in Markdown · Publish articles on custom domain · Gain readership on day zero · Automatic GitHub backup and more

Jan Vladimir Mostert's photo

NodeJS (just like Tomcat, Apache, etc) will probably do fine serving static files, while NGINX will give you much better performance since it was built in C and supports the sendfile system call which is as fast as you can get on a Linux OS.

See: blog.modulus.io/supercharge-your-nodejs-app..

The test I ran was 10,000 requests using 40 concurrent connections. Node.js averaged 862 requests/sec and Nginx averaged 1,608 requests/sec. This means Nginx can handle roughly double the throughput in my test environment.
Alexander Craggs's photo


Node.JS is built in C, just like NGINX is. The difference is NGINX is static and can do pre-optimizations which wouldn't make sense for Node.JS to do. That being said, do use NGINX if you are expecting a large amount of traffic, it is much faster.