When you start running an API nodeJS server, a frontend web server, and a test case, a NodeJS process is created. You may also use the command line or the Visual Studio code terminal to run all of these.
Angular, React, and Vuejs are examples of front-end frameworks.
Sometimes, You may need to stop a single process or all processes for debugging. Another way, You closed Visual Studio code without terminating the node process running in the terminal. For instance, suppose you’re using the ng command to execute an Angular application.
It stars the server and listens to 4100 ports.
Each service or operation in an operating system like Windows, Linux, or Unix creates a process, and each node does the same.
Process Id is assigned to each process.
You must first kill the process to stop it.
You will learn how to kill or stop node server - single node process - all node instances in this tutorial.
How to kill node process in Linux
In this example,
You can get a process id with a port number or named process
One way, get process ID for a given 8080 port using the below command.
netstat -lpn |grep :8080
Another way, get process ID for a given node process name using the below command.
ps aux | grep node
This gives an output something like this and it contains Process Id
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8795/node
you kill nodejs process by process id.
In this case, ProcessId is 8795
kill the process using -f forcefully option
kill -9 8795
This kills or stop a single specific node process.
How to stop all instances of node.js server in Unix
It is simple to kill all node processes using the below command
killall -9 node
How to stop single or instances of node.js server in windows
nodejs process is running an executable file node.exe in windows.
One way is stop single node process in Windows Find all process ids for a given port listening.
netstat -ano | find "LISTENING" | find "4100"
It lists out all process ids for given port 4100
TCP 0.0.0.0:4100 0.0.0.0:0 LISTENING 17846
you can kill the process using the taskkill command
taskkill /pid 17846
/f option for killing a single process forcefully.
taskkill /f /pid 17846
The second way, kill all node process in Windows
You need to kill this file using the below command
taskkill is a command to kill in process in Windows
taskkill /im node.exe
use /f option to kill it forcefully
taskkill /im /f node.exe
This stops and kill all node process in windows.
killall commands are available in Mac and Unix Operating systems. So It works on all ubuntu and UNIX flavors OS.
To Sum up, You learned how to stop and stop all processes in Windows and Unix.