How to kill a Node.js process running at a specific port in Linux?

January 9, 2021 - 2 min read

To Kill a Node.js process running at a port, you can use the lsof (List of Open files) Linux command.

For our use case, Let's consider we want to kill a Node.js process at port 3000.

For that, we can use the -i flag in the lsof command and then pass the internet addresses we want to match. The -i flag selects the lists of files any of whose Internet address matches the address specified in it.

It can be done like this,

lsof -i tcp:3000

# Or
# lsof -i tcp:<YOUR_PORT_NUMBER>

After that, it will show an output with all processes associated with the port number and its corresponding PID like this,

COMMAND   PID         USER
node    33092         johndoe

Now all you have to do is get the PID number.

After that use the kill command and pass the -9 flag to SIGKILL the process (This will tell the OS to stop running the process) and then pass the PID of the process.

It can be done like this,

kill -9 33092

Now you have successfully killed the Nodejs process running at PORT 3000. 🚀

Feel free to share if you found this useful 😃.