EADDRINUSE

Node.js ErrorNetwork ErrorCommonLast updated: June 28, 2026Tested on:Node.js v20 LTSNPM v10.2June 2026

The network port or address is already in use by another process.

EADDRINUSE Quick Fix⏱️ Est. Fix Time: 3 minutes

Usually happens because:

  • Background App Hanging
  • Duplicate Dev Tool Servers
  • TIME_WAIT Port Locking

🔍 Quick Checklist:

What is EADDRINUSE?

EADDRINUSE stands for 'Error: Address Already in Use'. It is thrown when Node.js attempts to bind a server or listener socket to a network port or IP address that is already active and occupied by another process on your operating system.

Common Causes

  • Background App Hanging: An older instance of your server failed to close properly and is still holding the port in the background.
  • Duplicate Dev Tool Servers: Another dev server (e.g. React/Vite/Docker) is already listening on the requested port.
  • TIME_WAIT Port Locking: The operating system has temporarily locked the port during socket recycling (TIME_WAIT).
CauseFrequency
Background App Hanging⭐⭐⭐⭐⭐
Duplicate Dev Tool Servers⭐⭐⭐⭐
TIME_WAIT Port Locking⭐⭐⭐

Common Mistakes

  • Failing to close VS Code terminals or PM2 background instances before starting node processes again.
  • Binding Docker container ports to host ports that are already occupied by host database services.

How to Fix

1Terminate Port Process: Identify and kill the process holding the port using command-line tools.
2Assign Dynamic Ports: Utilize environment variable ports (like process.env.PORT) to prevent static collisions.
3Handle Port Fallbacks: Detect EADDRINUSE on startup and bind the server to a different port.

Framework-Specific Examples

Checking for EADDRINUSE errors in Express and automatically falling back to an alternative port.

Express Port Increment Fallback Example
const startServer = (port) => {
  const server = app.listen(port, () => {
    console.log(`Server successfully started on port ${port}`);
  });

  server.on('error', (err) => {
    if (err.code === 'EADDRINUSE') {
      console.log(`Port ${port} is occupied. Trying port ${port + 1}...`);
      startServer(port + 1);
    }
  });
};

Server Configuration Examples

Configuring Apache to listen on alternative ports.

Apache Listen Directives Config
Listen 8080

Best Practices

  • Use variable PORT bindings derived from process.env.PORT configurations.
  • Check active ports using automated build check scripts.

Frequently Asked Questions (FAQ)

Q: How do I find out which process is using a port on Windows?

Open PowerShell and run `netstat -ano | findstr :3000` to find the process ID (PID), then kill it using `taskkill /PID <PID> /F`.

Q: How do I find and kill a port process on Linux/macOS?

Run `lsof -i :3000` to find the process ID (PID), then terminate it using `kill -9 <PID>`.

Q: What is the TIME_WAIT socket state?

When a server terminates, the operating system keeps the port reserved for a brief duration (typically 30-120 seconds) to ensure delayed packets are received. This can trigger temporary EADDRINUSE errors.

Q: Can I bind multiple applications to the same port?

No. Only one application process can listen for incoming connections on a specific port at any given time.

Still having this problem?

Didn't solve your problem?

SuggestRequest Error