Let's say I have a nodejs/express application on production server. If I want to add a new router, I have to reboot one, right? But if I reboot my node.js server, then users could get an error.
So how should I reboot my node.js server without errors for my users?
If you proxy to your Node.js app with Nginx, you can tell your Node app to listen on a socket and then only shut down the old server if the new one starts correctly; once the old server shuts down, Nginx will route requests to the new instance of the server. This is how Unicorn, a popular Ruby server, works.
In Nginx, you would specify your upstream like this:
upstream node_server {
server unix:/path/to/socket.sock;
}
server {
...
location / {
...
proxy_pass http://node_server;
}
}
And in node, you can listen on a socket with
server.listen('/path/to/socket.sock', function() {
console.log("Listening on socket.");
});
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