Search code examples
javascriptnode.jsexpresspassport.js

Update file without restart of server in Node.js


Is it possible to update a route,model or controller.js file without restarting the Node.js Server?.

I'm currently dealing with a client who wants constant changes to the application in a very frequent event. And the application deals with user session etc.. Whenever we make any changes to the application it requires a restart for the update to get reflect, which is very expensive in-terms of an high traffic situation.

I have seen some server application providing a feature called Rolling Restart but again I'm not sure whether it is a good way to maintain the user session across the restart event. Or do we have any other solution to deal with this kind of situation.


Solution

  • You can restart a server without downtime yes, I recommend you take a look at PM2 https://github.com/Unitech/pm2

    You can have multiple instances of node running and when you set a restart it does it gradually, making that you don't have downtime, it also distributes load to the different instances running so it speeds up your app, hope this helps :-)