I have a local node.js application in windows - is it possible to start \ kill local .EXE application and kill it in my code.
Is it possible? If so, I would be glad to see an example.
Thanks.
If you planning to kill your very own node process, the process API exposes the method exit(), which is indeed a wrapper to the C exit() method. According to the docs, it takes a parameter to specify success or failure.
One very "interesting" thing, then, would be to implement a controller to stop your server. Something like this:
app.post('/stop/server/now', function(){
process.exit(0);
});
EDIT To kill other processes, you simply need to know their pid (and have enough permission to kill other processes).
First, to get the pids, execute a command to do so. On Linux, this would be:
var exec = require('child_process').exec;
exec("ps aux | grep 'process_to_kill' | grep -v grep | awk '{print $2}'",
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
if (error !== null) {
console.log('exec output: ' + error);
}
});
Then, you pass these pids to the process.kill() API.