DEV Community

Rishabh Sharma
Rishabh Sharma

Posted on

Tired of EADDRINUSE? I Built a CLI to Deal With It

If you've worked with Node.js, you've probably encountered this at some point:

Error: listen EADDRINUSE: address already in use :::3000
Enter fullscreen mode Exit fullscreen mode

You try to start your development server, and suddenly port 3000 is already occupied.

Now begins the usual routine:

lsof -i :3000
Enter fullscreen mode Exit fullscreen mode

Find the PID.

kill -9 <PID>
Enter fullscreen mode Exit fullscreen mode

Then try starting your server again.

It's not exactly difficult, but having to repeat these steps gets annoying, especially when you're switching between projects or running multiple development servers.

So I built Purgeport.

What is Purgeport?

Purgeport is a cross-platform CLI that helps you find and terminate processes occupying specific ports.

Instead of manually looking up PIDs and killing processes, you can simply run:

npx purgeport 3000
Enter fullscreen mode Exit fullscreen mode

It identifies the process using the port, displays relevant process information, and lets you decide whether to terminate it.

Features

  • Find processes occupying specified ports.
  • Display process information before termination.
  • Interactive confirmation before killing processes.
  • Support for multiple ports.
  • Cross-platform support.
  • Simple CLI interface.

Installation

Install it globally using npm:

npm install -g purgeport
Enter fullscreen mode Exit fullscreen mode

Or run it directly with npx:

npx purgeport 3000
Enter fullscreen mode Exit fullscreen mode

You can also pass multiple ports:

purgeport 3000 5173 8080
Enter fullscreen mode Exit fullscreen mode

Why build another CLI for this?

There are already tools that solve this problem.

I wasn't trying to reinvent process management. I just wanted a small utility that makes this particular workflow less tedious, without remembering different commands or manually searching for process IDs.

Sometimes a small developer utility is all you need.

Try it out

Purgeport has already crossed 1,000+ npm downloads, which is pretty exciting for a small utility I built.

If you try it, feedback, bug reports, and contributions are welcome.

And hopefully, the next time you encounter EADDRINUSE, you won't have to go hunting for PIDs manually.

Top comments (0)