pm2 does not restart worker when express error occur pm2 does not restart worker when express error occur express express

pm2 does not restart worker when express error occur


When catching errors with express error handler or even "uncaughtException" event, the process is still running, so pm2 won`t restart it.If you want pm2 to restart after each exception, I would suggest something like this:

    process.on('uncaughtException', function(e) {      console.log('An error has occured. error is: %s and stack trace is: %s', e, e.stack);      console.log("Process will restart now.");      process.exit(1);    })

Same goes for the express error handler. When we execute process.exit method, the process will terminate and pm2 will restart it.