node.js app that can restart itself


How can I create an app that can restart itself? I want to create an app that sets up a web-admin which can restart itself. Is this possible? If so, how? I was thinking this might be possible with the process module that is built into node.

Problem courtesy of: LordZardeck


I have run Forever several times and it is easy to get started with. Check it out at:

Solution courtesy of: Marcus Granström


  1. you can run your app using child process and manipulate it how needed:

  2. use forever, pm2 or whatever thing to restart after death and kill itself with process.exit()

Discussion courtesy of: Lukas Liesis

I know it's a little late to reply however I had a similar requirement. I wanted to restart my node process whenever I made a configuration change. I'm using pm2 to manage my node processes so it turned out to be really easy.

After making a configuration change, i execute process.exit() from within the node process. As far as I can see, the process exits then pm2 restarts the process fine.

Not sure yet if there are any side effects but it seems to be working fine for me right now.

Discussion courtesy of: lewma

This recipe can be found in it's original form on Stack Over Flow.