Terminate Process on a Port from Command Line

By  on  

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.

Recent Features

Incredible Demos

  • By
    Introducing MooTools LazyLoad

    Once concept I'm very fond of is lazy loading. Lazy loading defers the loading of resources (usually images) until they are needed. Why load stuff you never need if you can prevent it, right? I've created LazyLoad, a customizable MooTools plugin that...

  • By
    Image Reflection with jQuery and MooTools

    One subtle detail that can make a big difference on any web design is the use of image reflections. Using them too often can become obnoxious but using reflections on large, "masthead" images is a classy enhancement. Unfortunately creating image reflections within your...

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!