1

I know that node.js server caches modules. So, after starting the server all files get "compiled" and all your changes to code can take effect after restart the server.

But if there are always hundreds of users online on website - how do you make those changes (restart server) in a way your hundreds of client won't notice any trouble, downtime?

Please, give me some guide and (your own) examples about (I guess) scalability, balancing load on servers etc, so I can make awesome large and dynamic website with node.js too.

Oleksii Shnyra
  • 623
  • 1
  • 6
  • 24
  • Possible duplicate of [How can I edit on my server files without restarting nodejs when i want to see the changes?](http://stackoverflow.com/questions/2925940/how-can-i-edit-on-my-server-files-without-restarting-nodejs-when-i-want-to-see-t) – FuzzyTree Feb 14 '16 at 22:28

1 Answers1

2

The best way to accomplish continuous uptime with Node.JS is to have 2 Node servers running and proxy to them using nginx and upstream providers. That way you can restart one whilst the other takes the traffic load then do the same to the other node server.

Your nginx configuration would use something similar to the below:

upstream backend {
    server backend1.example.com       weight=5;
    server backend2.example.com:8080;
    server unix:/tmp/backend3;

    server backup1.example.com:8080   backup;
    server backup2.example.com:8080   backup;
}

server {
    location / {
        proxy_pass http://backend;
    }
}

For more information about nginx proxying and upstream providers see the nginx documentation: http://nginx.org/en/docs/http/ngx_http_upstream_module.html

  • Agree with TheBANHAMMER,one point i would i like to mention,in case you are using pm2 in clustermode try to reload the server everytime you want to restart the node server(reload restarts the node server gracefully).So in case your one server is serving and in between you reload,it waits for that request to successfully process , then only reloads. pm2 gracefulReload all I am assuming you have already explored the idea of using pm2 in cluster mode.If not then go through this https://keymetrics.io/2015/03/26/pm2-clustering-made-easy/ – Nitish Agarwal Mar 08 '16 at 13:49