How to fix "Error: listen EADDRINUSE: address already in use"

Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with Node 22 and Python 3.12, November 29, 2026.

To solve “address already in use”, free the port or pick another one: something is already listening on the port your app wants. Find the process using it, then stop it or start your app on a different port:

lsof -i :3000          # Mac and Linux: shows the PID
kill <PID>

We reproduced it with Node 22 by starting two servers on the same port. The second one crashed with Error: listen EADDRINUSE: address already in use 0.0.0.0:3997. Once we stopped the first server, the second one started without errors.

What the error looks like

Error: listen EADDRINUSE: address already in use 0.0.0.0:3997
    at Server.setupListenHandle [as _listen2] (node:net:...)
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '0.0.0.0',
  port: 3997

The address and port at the end of the first line tell you which port is taken. You may see :::3000 instead, which is the IPv6 form of the same thing.

Fix: find and stop the process

Mac and Linux:

lsof -iTCP:3000 -sTCP:LISTEN -n -P
kill <PID>

If lsof isn’t installed on Linux, fuser 3000/tcp (or ss -ltnp | grep 3000 where ss is available) shows the same PID. In our test, lsof and fuser both pointed at the first Node server. Use kill -9 <PID> only if a plain kill doesn’t stop it.

Windows:

netstat -ano | findstr :3000
taskkill /PID <PID> /F

Fix: use a different port

If the other process should keep running (another project, a database, a system service), move your app instead:

const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`Listening on ${port}`));
PORT=3001 npm start

Fix: your own app starts twice

If the PID belongs to your own project, the usual causes are:

  • A dev server or nodemon left running in another terminal tab or a closed editor window.
  • Calling app.listen() twice, for example once in app.js and again in a test file that imports it.
  • Tests that start a server and never close it. Close it in afterAll(() => server.close()).

Python: [Errno 98] or [Errno 48]

Python reports the same problem as OSError: [Errno 98] Address already in use on Linux, which is what we saw, and as [Errno 48] on macOS. The usual cause is an earlier python -m http.server (or Flask dev server) still running in another terminal. Find it and stop it:

ps -fA | grep python
kill <PID>

It fails for a minute after you restart your own server

If nothing is listening but your server still can’t bind right after a restart, the old connections are in TIME_WAIT. In our test, a plain Python socket server that had just closed a connection failed to restart with [Errno 98]; with SO_REUSEADDR set before bind() it restarted straight away:

s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(("127.0.0.1", 8000))

Node sets this option itself; a Node server restarted the same way in our test bound without an error. In Python 3.12, http.server.HTTPServer sets it, but plain socketserver.TCPServer doesn’t: set allow_reuse_address = True on your server class.

On macOS, port 5000 or 7000

Recent versions of macOS use port 5000 and 7000 for AirPlay Receiver, so a Flask or Node app on 5000 can fail even when you haven’t started anything. Pick another port, or turn AirPlay Receiver off in System Settings. We didn’t test this one ourselves.

Confirm it worked

lsof -i :3000 prints nothing before you start the app, and your server logs its “listening” line instead of the error. If you’re debugging a client that can’t reach the server, that’s a different error: see ECONNREFUSED.

FAQ

Why is the port still busy after I closed my terminal?

The old server process can keep running in the background, especially if it was started by a watcher like nodemon or a dev server that didn't shut down cleanly. Find its PID with lsof -i :3000 and stop it.

How do I make my app use a different port?

Read the port from an environment variable, for example const port = process.env.PORT || 3000;, then start it with PORT=3001 npm start.

Is this error specific to Node?

No. Any program that opens a listening socket can hit it. Python raises OSError: [Errno 98] Address already in use on Linux for the same reason.