How to reload a Node.js server without downtime using PM2?

View other answers to this thread
Start a personal dev blog on your domain for free and grow your readership.

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

Sandeep Panda's photo

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.

More Info