node.jspm2application-restart

Force PM2 to restart from within the application - how to interact with PM2 from the running application?


I'm using PM2 to run a NodeJS app. Sometimes it's desirable to restart the app. Is there a way to do this from within the app, to avoid having to log into the server each time?

Would the simplest solution be to set PM2 to restart on changes in the app directory, then have the app touch a file? Or is there a way to interact with PM2 from within the app?


Solution

  • PM2 starts a process that ended, this means that if the process exits due to exception or natural exit, it will restart it.

    So, just run this when ever need

    process.exit(0)