Q:

How do you build node.js dynamic web server? (upgrade server without notice)

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.

A:

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

