node.js – Can the pm2 node module restarts the app after crash automatically

node.js – Can the pm2 node module restarts the app after crash automatically

Yes, it does this by default and there is even a watch option to restart on changes.

Also, check this new excellent option:

--exp-backoff-restart-delay=100

pm2 will restart the crashed app after 100 milliseconds (0.1 seconds), then step-by-step increase restart-delay to 15 seconds.

node.js – Can the pm2 node module restarts the app after crash automatically

To make app restart when it crashes you have to use one of PM2s restart strategies.

There is something called Exponential Backoff Restart Delay which PM2 explains as:

Instead of restarting your application like crazy when exceptions happens (e.g. database is down), the exponential backoff restart will increase incrementaly the time between restarts.

You can set it using the CLI like this:

pm2 start app.js --exp-backoff-restart-delay=100

There are other restart methods also, which are mentioned here.

Leave a Reply

Your email address will not be published.