How to reload a Node.js server without downtime using PM2?View other answers to this thread
3.4K+ developers have started their personal blogs on Hashnode in the last one month.
Write in Markdown · Publish articles on custom domain · Gain readership on day zero · Automatic GitHub backup and more
The simplest way to do this in PM2 is to start your server in cluster mode. Use the following pm2 command to do this :
pm2 start www -i 1
The above command will spawn a child process in cluster mode so that later on you can reload your app by using the following command :
pm2 reload www
Now PM2 will attempt to reload your process without any downtime. If due to some reason, PM2 can't reload the app, it'll fallback to a restart.