Skip to main content

Node.js · 5 common causes

EADDRINUSE

Updated

Something else is already listening on the port your server is trying to bind.

The exact message

node:events:492
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (node:net:1872:16)
    at listenInCluster (node:net:1920:12) {
  code: 'EADDRINUSE',
  errno: -48,
  syscall: 'listen',
  address: '::',
  port: 3000
}

Paths, line numbers and stack frames differ on every machine, and the wording is tightened between versions. The part that identifies the problem is EADDRINUSE.

How to fix it

Cause 1 of 5

A previous run of the same server is still alive.

Find it and stop it. On macOS or Linux: lsof -i :3000 prints the PID, then kill <pid>. On Windows: netstat -ano | findstr :3000 then taskkill /PID <pid> /F. Send a plain kill first so the process can shut down cleanly; only escalate to kill -9 if it ignores that.

Cause 2 of 5

Another application owns the port.

Move rather than fight: PORT=3001 npm run dev, or change the port in your server config. Port 5000 on macOS is a common collision because AirPlay Receiver listens there.

Cause 3 of 5

A Docker container publishes the same host port.

docker ps shows the mappings. Stop that container with docker stop <name>, or republish it on a different host port with -p 3001:3000 — the left number is the host side and nothing inside the container changes.

Cause 4 of 5

The code calls listen() more than once.

Look for a second app.listen() — one in the module body and one in a test bootstrap is the classic pair. A watcher that re-executes the entry file without closing the old server produces the same symptom, so close it in the hot-reload dispose hook.

Cause 5 of 5

The process is a zombie held open by a child.

If the PID keeps coming back, the parent is respawning it. Stop the supervisor — the nodemon, pm2 or compose process that owns it — rather than the individual worker: pm2 list then pm2 stop <name>.

Stopping it coming back

Read the port from an environment variable with a fallback so a colliding service is a one-word change, and close the server in your test teardown so suites never leak a listener.

EADDRINUSE — common questions

What does the ::: in the message mean?
It is the IPv6 wildcard address, so the server tried to bind every interface on that port. A message with 0.0.0.0 means the IPv4 wildcard, and 127.0.0.1 means loopback only. The distinction matters when two processes bind the same port on different interfaces.
Is npx kill-port safe to use?
It does the same lookup-and-kill you would do by hand, so it is fine for a development port you own. Never point it at a port on a shared or production machine — you cannot see from the port number alone what you are terminating.
Why does the port stay busy for a while after I stop the server?
A socket in TIME_WAIT lingers for a couple of minutes so late packets from the old connection cannot be delivered to a new one. Node sets SO_REUSEADDR on listening sockets, so this rarely blocks a restart — if the port is genuinely still bound, a process still holds it.

Test the fix before you paste it back

Reproducing the failure in a scratch file is usually faster than editing the real one. AltF Code is a free in-browser editor with real syntax highlighting for HTML, CSS, JavaScript, TypeScript, Python, SQL and JSON, and it runs HTML, CSS and JavaScript live in a preview panel. No install and no sign-up.

Open the editor