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

Tom Nagle
1 min readJan 15, 2021

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).

🌎 Let’s keep in touch

Subscribe on YouTube
Discord
Twitter
TikTok
FaceBook
Instagram
Buy me a Coffee

--

--

Tom Nagle

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