{

Different ways to kill or stop node process in Windows and Linux


Package.json tutorial and Example

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. Other way, You closed Visual Studio code without terminating the node process running in terminal. For instance, suppose you’re using the ng command to execute an Angular application.

ng serve

It stars the server and listens 4100 port.

Each service or operation in an operating system like Windows, Linux, or Unix creates a process, and each node does the same.

Process Id assigned to each process.

You must first kill the process in order 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 process id with port number or named process

One way, get process ID for a given an 8080 port using below command.

netstat -lpn |grep :8080

Other way, get process ID for a given node process name using 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 single specific node process.

How to stop all instances of node.js server in Unix

It is simple to kill all node process using below command

killall -9 node

How to stop single or instances of node.js server in windows

nodejs process are running an executable file node.exe in windows.

One way, stop single node process in Windows Find all process ID’s for a given port listening.

netstat -ano | find "LISTENING" | find "4100"

It list out all process ids for given port 4100

  TCP    0.0.0.0:4100           0.0.0.0:0              LISTENING       17846

you can kill process using taskkill command

taskkill /pid 17846

use /f option for killing single process forcefully.

taskkill /f /pid 17846

Second way, kill all node process in Windows

You need to kill this file using below command taskkill is an 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

Conclusion

Above all, kill and killall commands are available in Mac and Unix Operating System. So It works on all ubuntu and UNIX flavors OS.

To Sum up, You learned how to stop and stop all process in Windows and Unix

THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.