How to Check If a Port Is in Use on Mac
macOS Sequoia and Tahoe; older versions noted where they differ · Last checked · Suggest an edit
https://instructions.wiki/mac/check-if-a-port-is-in-use-on-mac
You start a dev server and get EADDRINUSE: address already in use. Something is already listening on that port. Here is how to find it and free the port in under a minute.
Run lsof on the port
Open Terminal and run this, replacing 3000 with your port:
lsof -nP -iTCP:3000 -sTCP:LISTEN
lsof lists open files, and on Unix a network socket counts as a file. The flags mean: -n and -P skip slow hostname and port-name lookups, -iTCP:3000 limits results to TCP on port 3000, and -sTCP:LISTEN shows only processes actually listening.
If nothing prints, the port is free.
Read the output
A hit looks like this:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 48213 sam 23u IPv6 0x1a2b3c 0t0 TCP *:3000 (LISTEN)
The two columns you care about are COMMAND (what it is) and PID (the process ID you will use to stop it).
Stop the process
Send it a normal termination signal using the PID from the previous step:
kill 48213
Most processes exit cleanly. If it is still there after a few seconds, force it:
kill -9 48213
Use -9 only as a fallback. It skips the process's cleanup, which can leave temp files or lock files behind.
Confirm the port is free
Run the first command again:
lsof -nP -iTCP:3000 -sTCP:LISTEN
No output means the port is yours. Start your server.
One-liner for next time. If you do this often, this finds and kills whatever is on the port in one step:
kill $(lsof -t -iTCP:3000 -sTCP:LISTEN)
-t prints only PIDs, which kill then receives. It errors harmlessly if the port is already free.