Sometimes when running code locally, you may see an error with:
Error: listen EADDRINUSE: address already i use 127.0.0.1:4567
To find what's using it (and potentially stop it), you can use a combination of the
lsof -P -i :<PORT> replacing
<PORT> with the port you want to check.
-P with the
lsof flag will keep you from being confused by the
NAME column containing common services that run on those ports (port 4567 for
bcm-reporting and 4568 for
tram for example).
lsof and run
ps <PID> to find what's running on this port. If it's okay to kill it, run
kill <PID> and try to re-run your command again.
If you're interested in seeing what service MacOS expects to be serving on a specific port, you can run the following command and replace
4567 with the port you're curious about:
cat /etc/services | grep " 4567/tcp"