nodejs kill process code example

Example 1: node js quit

process.exit();

Example 2: kill node process

The Difference Between kill and pkill
The kill command is a wrapper to the kill system call, which knows only about process IDs. pkill can determine the process ID based on things like, process name, owner of the process or session id.

Syntax:
$ kill 1234
$ pkill -f node

Example 3: kill node process windows

taskkill /im node.exe /F

Example 4: js kill process

process.kill(process.pid, 'SIGINT');

Example 5: node js kill process

process.exit()

//or

if (condition){process.exit()}

//or

setTimeout((function() {
    return process.exit();
}), 5000);
// kill server after 5000ms

//source :
//https://stackabuse.com/how-to-exit-in-node-js/