Kill a running node process in windows

Am trying to stop a node script from a running node server in windows

an running the script as node appium -p 3000

and it will be in running state until it stop i need to stop this script running in particular situation in windows how to kill this node script node appium -p 3000 i dont need to kill it by using PID.is tjere any possible ways to kill the running process

code

    var start = spawn('node appium -p 3000', args);
start.stdout.on('data', function(data) {
    console.log(data)
});
start.stderr.on('data', function(data) {
    console.log('ps stderr: ' + data);
});
start.on('close', function(code) {
    console.log('process exit code ' + code);
});


function killall(){

start.kill()//is it possible??/
process.exit() //is it also possible??

}

  • Kill it by PID

    Stop-Process 3512
    
  • Kill it by process name

    Stop-Process -processname node*
    
  • Make someone else kill it, if it's launched as a child_process

    var exec = require('child_process').exec;
    
    var child = exec('node appium -p 3000');
    
    // Kill after 3 seconds
    setTimeout(function(){ child.kill(); }, 3000);
    
  • Kill itself

    process.exit();
    
  • If it's not a background process, kill it with CTRL+C.

You stated in your comment that it is indeed launched as a child process but you need to kill it in another function. This is a question of variable scope. The following will NOT work:

function launch(){
    var child = spawn(cmd, args);
}

function kill(){
    child.kill(); // child is undefined
}

You just need to make sure child exists in your scope:

var child;

function launch(){
    child = spawn(cmd, args);
}

function kill(){
    child.kill();
}