Last active
August 7, 2022 06:21
-
-
Save luozhihua/7018285 to your computer and use it in GitHub Desktop.
Auto restart nodejs process when program exit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var child_process = require('child_process'); | |
start(); | |
function start(nodefile) { | |
if (typeof start !== 'string') { | |
console.log('Has none file. like this: start("app.js")'); | |
} | |
console.log('Master process is running.'); | |
var proc = child_process.spawn('node', [nodefile]); | |
proc.stdout.on('data', function (data) { | |
console.log(data.toString()); | |
}); | |
proc.stderr.on('data', function (data) { | |
console.log(data.toString()); | |
}); | |
// 监测退出事件,删除原进程并开启新进程 | |
proc.on('exit', function (code) { | |
console.log('child process exited with code ' + code); | |
delete(proc); | |
setTimeout(start, 5000); | |
}); | |
} |
What are doing within the delete function?
What are doing within the delete function?
What are doing within the delete function?
What are doing within the delete function?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What are doing within the delete function?