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
global variable that is built into node.
Run the dev scriptTo manually restart your Node. js application you can type rs in the command line. Important: If your application writes to files, like updating a config file, nodemon will prematurely restart your application.
Nodemon allows you to automate the process of restarting Node applications when you make changes to the underlying files.
In this case, if we make any changes to the project then we will have to restart the server by killing it using CTRL+C and then typing the same command again. It is a very hectic task for the development process.
LK"I
It is possible without external dependencies:
console.log("This is pid " + process.pid); setTimeout(function () { process.on("exit", function () { require("child_process").spawn(process.argv.shift(), process.argv, { cwd: process.cwd(), detached : true, stdio: "inherit" }); }); process.exit(); }, 5000);
source : https://gist.github.com/silverwind/d0802f7a919ae86ff25e
I have run Forever several times and it is easy to get started with. Check it out at: https://github.com/nodejitsu/forever
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With