The easiest way to kill a process by port number on a Mac

Almost every NodeJS developer would be familiar with the error message Error listen EADDRINUSE: address already in use. The message simply means that the application could not start because there is already a process using that port. Here is the easiest way I have found to stop a process running on your Mac that is using a specific port.

  1. Add a new file called stop to this directory: usr/local/bin

You can easily do this by typing: usr/local/bin/stop

2. Past the following script into the file:

3. Save the script and start using it

You can use the script by typing stop 3000 in to your terminal from any directory, where 3000 is the port number that has a process on it that you want to kill.

The script should output Killed process 12345 running on 3000 , where 12345 is the process id(PID).

I am a full stack JavaScript developer, living in Melbourne, Australia. My preferred stack is Mongoose, TypeScript, Node.js, React & GraphQL.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store