You can do something like this:
When you start the application, start it via another script. This will spawn the child process and kill it as needed.
mother.js
var child;
var spawn = require('child_process').spawn;
var argv = process.argv;
argv.shift();
argv.shift();
function startChild(){
console.log("STARTING", process.execPath, "child.js", argv);
child = spawn(process.execPath, ["child.js", argv], {
cwd: process.cwd(),
env: process.env,
detached: true
});
child.on('error', function(e){console.log(e)});
child.stdout.pipe(process.stdout);
console.log("STARTED with PID:", child.pid);
}
process.on('SIGQUIT', function() {
child.kill();
startChild();
});
startChild();
child.js
(function(){
console.log("Started child process");
setInterval(function(){console.log("running")}, 1000);
})();
You can then send ctrl+c to kill the thing. To reload send ctrl+\ or invoke in mother.js from your update function.