Notion app logo
Struggling to stay organized and effective? Learn to master your time and tasks with the Effectively Notion course!

Use lsof and ps to Find Running Services

Learn how to use the lsof and ps utilities to find running services when debugging EADDRINUSE in NodeJS logs.

2019-11-12

Sometimes when attempting to run a NodeJS server locally, you may see an error with:

Error: listen EADDRINUSE: address already i use 127.0.0.1:4567

To determine what's listening on this port (and potentially stop it), you can use a combination of the lsof and ps commands.

First, use lsof -P -i :<PORT> replacing <PORT> with the port you want to check.

We use the -P with lsof since we likely don't need the mapping for the port to a name in the network files1.

Take the PID from 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.

Footnotes

  1. By using lsof -P, it ignores the host machines conversion of port numbers to port names for network files. For example, if we ran lsof without -P, the NAME column would contain services that run on those ports, such as port 4567 for bcm-reporting or 4568 for tram. 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". ↩

Photo of Chase Adams

Hey, I'm Chase. I help aspiring entrepreneurs and makers turn their ideas into digital products and apps.

Freebies

Vector Arrow Scribbles
banner image for figma vector arrows scribbles

A figma community project of vectorized hand-drawn arrows.

Go To Figma
Vector Line Scribbles
banner for figma vector line scribbles

A figma community project of vectorized hand-drawn lines.

Go To Figma
Vector Shape Scribbles
banner image of figma vector shapes scribbles

A figma community project of vectorized hand-drawn shapes.

Go To Figma

Subscribe to my Newsletter

Every other week I publish the Curiously Crafted newsletter.

In it, I explore the intersection of curiosity and craft: the people who make stuff, what they make and the way they pursue the craft of making.

Online

I'm on almost all social media as @curiouslychase.

The curious logo of Chase Adams: glasses and a bow tie.stay curious.