How can I restart a Node.js app from within itself (programmatically)?

node.js

Solution

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

Problem

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.

Original source

Related problems