/* Code-Comments */

April 18, 2019

Error Handling: Address In Use

Running my node server, I got an error indicating that my port was already in use (Error: listen EADDRINUSE :::5001).

I knew that shouldn’t have been the case because I had only one application running on that port.

error - port in use

Still, killing the process multiple times from the console didn’t work, so I went in search of the process ID (PID) to kill it specifically.

There are multiple ways to do this, but the one that worked for me out of the box (on Mac) was lsof which is the “list open files” program.1

The -i flag allows for inclusion of specific ports.

In my case, I was interested in port 5001, so the command was lsof -i :5001.

This returned exactly what I needed: lsof

Apparently the node server hadn’t terminated and was still using the port, but now I knew the PID. This meant I could hop over to Activity Monitor, look it up and kill it. kill activity in activity monitor

Update: It’s possible to kill the process directly from the shell using the kill command, e.g., kill 5001.

Now when I restarted the server it worked like a charm.


Stephen Weiss

Thanks for reading! My name's Stephen Weiss. I live in Chicago with my wife, Kate, and dog, Finn.
Click here to see the archives of my weeks in review and sign up yourself!