Find and kill process locking specific port on Mac

February 18, 2020

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.

Profile picture

Experience in software development, application architecture, and deploying cloud solutions for enterprise customers. Strong hands-on skills with a Master's degree in Computer Science and business acumen with a master of business administration (MBA) in Finance. Certified in Amazon Web Services (AWS), Google Cloud Platform (GCP), Microsoft Azure, Kubernetes (CKA, CKAD, CKS, KCNA) and Scrum (PSM, PSPO) with experience in building banking products from scratch. Connect on Linkedin

© 2022, @victorleungtw