Lingua-e
← Errors
JavaScript

EADDRINUSE: address already in use: What It Means and How to Fix It

Error reference

EADDRINUSE: address already in use

Language

JavaScript

Severity

High

When it happens

EADDRINUSE happens when a process tries to bind to a port that is already occupied by another process.

Potential fixes

Find and kill the process using the port: lsof -i :<port> on macOS/Linux, or netstat -ano | findstr :<port> on Windows. Use an environment variable for the port number so different environments can use different ports. Add an error handler on the server object to fail with a clear message instead of an unhandled crash.

Deep dive

EADDRINUSE happens when a process tries to bind to a port that is already occupied by another process. It is not specific to Node.js — the operating system only allows one process to listen on a given port at a time, whether that process is a Node server, a Python script, or any other program, on Windows, macOS, or Linux.

Why it happens

  • •A previous instance of the same server process did not exit cleanly and is still holding the port.
  • •A different application (a database, another dev server, a proxy) is already listening on that port.
  • •Hot-reload or watch mode restarted the process before the old TCP socket was fully released.
  • •Running multiple test suites or server instances in parallel without assigning different ports.
  • •The same conflict shows up outside Node.js too — a Python server, a Windows service, or anything else trying to bind a port someone else already has.

Potential fixes

Find and kill the process using the port: lsof -i :<port> on macOS/Linux, or netstat -ano | findstr :<port> on Windows. Use an environment variable for the port number so different environments can use different ports. Add an error handler on the server object to fail with a clear message instead of an unhandled crash.

Examples

JavaScript

Code that triggers the error

const http = require("http");

const server = http.createServer((req, res) => {
  res.end("Hello");
});

server.listen(3000, () => console.log("Listening on port 3000"));

Error output

Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (node:net:1739:16)

Fixed code

const http = require("http");

const PORT = process.env.PORT || 3000;

const server = http.createServer((req, res) => {
  res.end("Hello");
});

server.on("error", (err) => {
  if (err.code === "EADDRINUSE") {
    console.error(`Port ${PORT} is in use. Kill the process or use a different port.`);
    process.exit(1);
  }
});

server.listen(PORT, () => console.log(`Listening on port ${PORT}`));

Practice in English

How would you explain an EADDRINUSE: address already in use to a fellow dev? Choose the right phrase:

"I hit an error...

Debugging in English?

You just read real developer English to fix this. Lingua-e has free exercises built the same way: standups, code reviews, and real workplace scenarios.

Practice developer English, free