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.
' that's provably false. Node does its low level socket handling in C just like nginx does, and implements streams, async io and other low level concepts.
If you're prepared to re-write your PHP in JavaScript, then yes, Node. js can replace your Apache. If you place an Apache or NGINX instance running in reverse-proxy mode between your servers and your clients, you could handle some requests in JavaScript on Node.
Conclusion. Node. js is a JS runtime environment that is also an HTTP server with some event-driven features and has many drawbacks in terms of concurrency and high load or user requests to handle a large number of users concurrently. Nginx has the best performance in this case, and it provides the best performance.
AngularJS, PHP, Python, JavaScript, and React are the most popular alternatives and competitors to Node. js.
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 engine plus libraries/modules. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With