Troubleshooting & Comparisons

How to Fix the EADDRINUSE 'Port Already in Use' Error

Learn how to troubleshoot and resolve the EADDRINUSE error effectively on Windows, Mac, and Linux systems.

3 min read

Learn how to troubleshoot and resolve the "port already in use" EADDRINUSE error, which commonly occurs when starting development servers like Node.js. This guide provides solutions for Windows, Mac, and Linux.

Identifying the Issue

The "EADDRINUSE" error occurs when an application tries to bind to a port that's already in use by another process. It typically appears during software development when starting local servers, such as Node.js on port 3000. To resolve this issue, you need to identify and terminate the process occupying the port.

Resolving the Error on Windows

To address the issue on Windows:

steps

  1. Locate the process using the port:

    bash
    netstat -ano | findstr :3000

    This command lists the process ID (PID) associated with port 3000.

  2. Terminate the process using its PID:

    bash
    taskkill /PID <PID> /F

    Replace <PID> with the actual PID obtained in the previous step.

  3. Verify the port is free by restarting your server application.

Fixing the Error on Linux/Mac

On Linux or macOS systems, follow these steps:

steps

  1. Identify which process is using port 3000:

    bash
    lsof -i TCP:3000

    The output displays the PID and process name.

  2. Terminate the process using its PID:

    bash
    kill -9 <PID>

    Replace <PID> with the PID obtained in the previous command.

  3. Confirm the port is no longer in use and restart your application.

Special Cases: Ghost Processes and Port Reservation on Windows

Takeaway

Resolving the "port already in use" EADDRINUSE error involves identifying and terminating the conflicting process. By using tools like netstat, taskkill, lsof, or kill, you can free the desired port and restart your application. Prevent similar issues by proactively checking active ports before assigning them in development.

FAQ

Why does the "EADDRINUSE" error occur frequently during development?

The error occurs when a development server, like Node.js, attempts to bind to a port that another process is already using. This commonly happens during frequent reboots or crashes of such servers.

How do I find which process is using a port without killing it?

On Windows, use netstat -ano | findstr :<PORT> and check the PID against running processes in Task Manager. On Linux/macOS, try lsof -i TCP:<PORT> to identify the process.

What if killing the process doesn't free the port?

This could indicate a reserved port (Windows) or a ghost process. Restart your system or use advanced utilities like netsh to remove reservations on Windows.


Official reference: Node.js API documentation.