Find and kill process locking specific port on Mac

Problem: Sometimes when you start a local node.js server, it may be stuck running at the background. When you try to start the server again, you will hit error saying that the port (for example 8080) is already is in used and locked:

throw er; // Unhandled ‘error’ event
Error: listen EADDRIUSE

Solution: You can try to find the process using lsof command:

lsof -n -i4TCP:8080

Or replace 8080 with the port number that you want to find. Then you will see a list of processes. Find the process that you want to kill, for example node is running with PID 6709, then kill that process with command:

kill -9 <PID>

Finally, start the server again and it will be running as normal after you free the port in use.

Originally published at on February 18, 2020.

By Victor Leung

Experience in software development, consulting services and technical product management. Understanding of business and technology with an MBA in Finance and a Master degree in Computer Science. AWS Certified Solution Architect with experience in building products from scratch and serving as a charismatic leader.

Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: