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 is thrown in Node.js when a server 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 is thrown in Node.js when a server tries to bind to a port that is already occupied by another process. The operating system only allows one process to listen on a given port at a time.

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.

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...

Ready to practice your English at work?

Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.

Try Lingua-e for free