Search code examples
javascriptnode.jspm2

PM2 restart delay Node.js


I'm using this code in my own app:

pm2.restart('myapp', function() {});

Works fine, but how can I include delayed restart to that?

--restart-delay=3000


Solution

  • As mentioned in the API docs you should define this configuration "restartDelay" in your Start function, the restart only stop and start it again:

      pm2.start({
        name         : 'myapp',   // Script name
        script       : 'app.js',  // Script to be run
        exec_mode    : 'cluster', // Allows your app to be clustered
        restartDelay : 3000,      // Number of ms to wait before restarting the script
      }, function(err, apps) {
        pm2.disconnect();   // Disconnects from PM2
        if (err) throw err
      });