Error Encyclopedia

EADDRINUSE: Port Already in Use Error

Fix 'EADDRINUSE: address already in use' errors. Learn how to find and kill processes using a port, or configure port fallbacks.

What Does This Error Mean?

The EADDRINUSE error means the network port your application is trying to bind to is already occupied by another process. Each port can only be used by one process at a time.

Common Causes

1

Another instance of your app is already running

2

Previous process did not exit cleanly (zombie process)

3

Another application (like Apache, Nginx, or Docker) is using the port

4

IDE or dev server from a previous session is still running

5

Port configured in a range that conflicts with system services

How to Fix It

Find and kill the process on the port

Identify the process ID using the port and terminate it.

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

# Linux/macOS
lsof -i :3000
kill -9 <PID>
# or
fuser -k 3000/tcp

Use a different port

Change the port your application listens on.

# Node.js: use environment variable
const PORT = process.env.PORT || 3000
app.listen(PORT)

# Next.js
npx next dev -p 3001

# Docker: map different host port
docker run -p 8080:3000 myapp

Set SO_REUSEADDR

Allow immediate port reuse after process termination.

// Node.js: enable SO_REUSEADDR
const server = app.listen(3000)
server.on("listening", () => {
  server.address()
})
// By default, Node.js enables SO_REUSEADDR on macOS and Linux

Use port fallback logic

Automatically try the next available port if the default is taken.

function startServer(port, maxAttempts = 10) {
  const tryPort = (p) => {
    app.listen(p).on("error", (err) => {
      if (err.code === "EADDRINUSE" && p < port + maxAttempts) {
        console.log(`Port ${p} in use, trying ${p + 1}`)
        tryPort(p + 1)
      } else {
        throw err
      }
    })
  }
  tryPort(port)
}

Related Tools

Use these tools to debug and fix this error:

Related Errors

Other common errors in this category: