Error: listen EADDRINUSE: address already in use :::3000

Node.js · updated 2026-11-05

Thrown as an unhandled 'error' event the moment server.listen() runs, so the app exits during startup. The ':::3000' part is the IPv6 wildcard address, which on most systems also covers IPv4.

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

Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (node:net:1908:16)
    at listenInCluster (node:net:1965:12)
    at Server.listen (node:net:2067:7)
    at file:///app/server.js:14:8 {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '::',
  port: 3000
}

Quick fix

Find and stop whatever already holds port 3000, then start the server again. On macOS or Linux, lsof prints the PID of the listener; kill it, or pick a different PORT. If an orphaned dev server keeps coming back, fix the restart flow that leaves the old process alive.

  1. Run lsof -nP -iTCP:3000 -sTCP:LISTEN (macOS/Linux) or netstat -ano | findstr :3000 (Windows).
  2. Check what that PID is with ps -p <PID> -o command.
  3. Stop it with kill <PID>; use kill -9 only if it ignores SIGTERM.
  4. Read the port from process.env.PORT so switching needs no code change.
  5. Handle SIGTERM and SIGINT by calling server.close() so restarts release the port.
bash
# Who is listening on 3000?
lsof -nP -iTCP:3000 -sTCP:LISTEN

# Ask it to exit (replace 12345 with the PID from above)
kill 12345

# Linux alternative: kill whatever owns the port
fuser -k 3000/tcp
Fix it with your coding agent

Paste this into Claude Code, Cursor or Codex in the project that throws it. The agent reads this guide in plain text and applies the fix that matches your stack.

prompttext
Read https://runheed.com/errors/eaddrinuse.md and fix this error in this project.

Why it happens

An old copy of the server is still running

A closed terminal tab, a crashed editor or a detached watcher (nodemon, tsx watch) can leave the previous server alive in the background. That process still owns the listening socket, so the new one cannot bind to the same port.

A child process survived its parent

Tools that spawn a worker to serve requests (next start, cluster workers, some dev servers) can leave the child running when only the parent gets killed. Process managers need tree-kill behavior, otherwise the orphaned child keeps the port.

Another program already uses that port

A Docker container published with -p 3000:3000, a second project, or a system service is listening there. On recent macOS versions, AirPlay Receiver occupies ports 5000 and 7000, which trips up Flask-style defaults and some Node setups.

listen() called twice in the same process

The app module calls app.listen() at import time and the entry file or test suite calls it again. Hot-reload setups that re-run the module without closing the previous server hit the same wall on every reload.

Overlapping restarts in production

A deploy script starts the new process before the old one has released the port, or two pm2 or systemd units point at the same app. Without a graceful shutdown, the old process can hold on for its full kill timeout.

Other fixes

  • In tests, export the app without calling listen and use listen(0) so each test file gets a free random port.
  • Under pm2, enable treekill with a kill_timeout so worker children die with the parent.
  • Listen for server.on('error') and print a clear 'port in use' message instead of the raw unhandled event.
  • Turn off AirPlay Receiver in macOS System Settings if it holds port 5000 or 7000.

Same error, other wording

  • Error: listen EADDRINUSE :::3000
  • Error: listen EADDRINUSE: address already in use 0.0.0.0:3000
  • Error: listen EADDRINUSE: address already in use 127.0.0.1:8080

Let your coding agent catch the next one

Runheed records this error in production with the stack trace, the breadcrumbs before it and, when you set it, the agent session that shipped the code, and serves it to Claude Code, Cursor or any MCP client. With it connected, you can ask:

> Look up the EADDRINUSE crashes from the last deploy, tell me which port and host they hit, and add a SIGTERM handler that closes the HTTP server before exit.

Setup for Node.js and Express or Vercel Functions, then have your agent fix and resolve it.

Related errors

More in Memory, async and the process

Other error topics

Free tools: Source map stack trace decoder · Uptime and SLA downtime calculator · Error budget calculator · Stack trace formatter · JSON log viewer · HTTP status code reference.

References: Node.js net module: server.listen(), Node.js errors: common system errors

Spotted a mistake? Email hello@greatwork.company. About Runheed.