As far as I understand, a Node.js server is basically a JavaScript file, run by the node
executable. Is it possible to update this file without stopping request handling?
I guess the node executable must be stopped for this, so I think I should use a reverse proxy. For example:
Is this a valid approach? How can such a version update be done automatically on multiple server machines (accessible from the same LAN)?
Note: By default, subsequent node pools do not have auto-upgrades enabled.
Update Files The File System module has methods for updating files: fs.appendFile() fs.writeFile()
A different "pure-node" solution is to use the built-in cluster module:
Your code runs as one cluster-client (of many). A cluster-server process binds to the port and does automatic load-balancing between clients. When you've changed the code, you can send a signal to the cluster-server and it will gracefully restart your clients, without dropping any existing connections.
Here are some projects that can do the cluster-server management for you:
Advantages:
Basically, what you can (should) do is the following:
When you need to update your system, shut down one of the two Node.js instances, update it, and restart it. Then do the same with the other.
Basically, this should do it.
The downside is that you are potentially running different versions of your application for a small amount of time concurrently, and your database (e.g.) needs to be able to catch up with this.
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