PASSWORD RESET

Your destination for complete Tech news

How to kill a node process?

450 0
< 1 min read

To kill a Node.js process, you can use one of the following methods:

1. process.exit(): You can use the process.exit() method to exit the current Node.js process with an optional exit code. This method will cause the process to exit immediately, without waiting for any asynchronous operations to complete. For example:

process.exit(0);  // exit with a success code
process.exit(1);  // exit with an error code

2. process.kill(): You can use the process.kill() method to send a signal to a Node.js process. This method takes two arguments: the process ID and the signal to send. For example, to kill a process with the process ID 123, you can use the following command:

process.kill(123, 'SIGKILL');

Note that process.kill() will only work if you have the necessary permissions to send signals to the process.

3. Ctrl + C: If you are running the Node.js process in a terminal, you can use the Ctrl + C keyboard shortcut to kill the process. This will send the SIGINT signal to the process, which will cause it to exit.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.