Terminate Process on a Port from Command Line

Once a week I have to deal with a zombie process or try to start a process that’s already running on its designated port. In most cases I use macOS’s Activity Monitor to kill the process, which is time-consuming. What if we could just kill a process on a given port from command line? Well, […]

The post Terminate Process on a Port from Command Line appeared first on David Walsh Blog.

Once a week I have to deal with a zombie process or try to start a process that’s already running on its designated port. In most cases I use macOS’s Activity Monitor to kill the process, which is time-consuming. What if we could just kill a process on a given port from command line? Well, we can!

To terminate a process on a given port, install kill-port and starting nuking those zombies via:

# yarn global add kill-port

# Kill processes on multiple ports
kill-port 6060 8000

If you want to programmatically kill a port that you want to ensure your app will run on, you can do that as well:

const kill = require('kill-port')

kill(6060, 'tcp')
      .then(console.log)
      .catch(console.log)

I look forward to incorporating this library into my Node.js sites so that I can clear the way for a given port and avoid zombie processes.

The post Terminate Process on a Port from Command Line appeared first on David Walsh Blog.


Print Share Comment Cite Upload Translate
APA
David Walsh | Sciencx (2024-03-28T14:12:16+00:00) » Terminate Process on a Port from Command Line. Retrieved from https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/.
MLA
" » Terminate Process on a Port from Command Line." David Walsh | Sciencx - Sunday October 10, 2021, https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/
HARVARD
David Walsh | Sciencx Sunday October 10, 2021 » Terminate Process on a Port from Command Line., viewed 2024-03-28T14:12:16+00:00,<https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/>
VANCOUVER
David Walsh | Sciencx - » Terminate Process on a Port from Command Line. [Internet]. [Accessed 2024-03-28T14:12:16+00:00]. Available from: https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/
CHICAGO
" » Terminate Process on a Port from Command Line." David Walsh | Sciencx - Accessed 2024-03-28T14:12:16+00:00. https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/
IEEE
" » Terminate Process on a Port from Command Line." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/. [Accessed: 2024-03-28T14:12:16+00:00]
rf:citation
» Terminate Process on a Port from Command Line | David Walsh | Sciencx | https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/ | 2024-03-28T14:12:16+00:00
https://github.com/addpipe/simple-recorderjs-demo