Error fixes
Fix Error: listen EADDRINUSE Address Already in Use
EADDRINUSE means another process is already listening on the port your server tried to open, very often an earlier copy of the same dev server that never shut down. Find the process ID with netstat or lsof, stop it, or start your app on a different port set through the PORT environment variable.
By CodingMarble · Published · 4 min read

What the error means
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (node:net:1817:16)
at listenInCluster (node:net:1865:12)
at Server.listen (node:net:1953:7) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '::',
port: 3000
}A port can be bound by only one process at a time for a given address. When your code calls listen(3000), the operating system checks whether something already holds that port. If it does, the call fails and Node throws. The three colons in :::3000 are the IPv6 wildcard address followed by the port, so the full meaning is "every address on port 3000". The errno value differs by operating system, so rely on the code string EADDRINUSE rather than the number.
The conflicting process is not always Node. Another framework's dev server, a database admin tool, a container with a published port, or a system service can all hold the number you wanted. The fix is the same: identify the holder before you decide what to do about it.
It also helps to know what the error is not. It is not a firewall problem, a permissions problem or a bug in Express. Binding to a port below 1024 on Linux without elevated rights produces a different code, EACCES, and an unreachable port from outside the machine produces timeouts, not this message. If you see EADDRINUSE, something local holds the socket, and the rest of this guide is about finding it quickly.
Why it happens, most likely first
- A previous run of your own server is still alive. A closed terminal tab, a crashed editor or a parent process that exited can leave the child running in the background.
- You started the server twice, for example once from the terminal and once from an editor debug configuration.
- A watcher restarted your app before the old process released the port, which is common with misconfigured nodemon or ts-node-dev setups.
- A different project on your machine is using the same default port; many tools default to 3000 or 8080.
- In containers or hosting panels, the platform assigns the port and your hard-coded number collides with it or with another app on the same account.
Find and stop the process
On Windows, netstat lists connections with the owning process ID, and taskkill ends the process. Run these in PowerShell or Command Prompt.
netstat -ano | findstr :3000
# The last column is the PID, for example 14232
tasklist /FI "PID eq 14232"
taskkill /PID 14232 /FOn macOS and Linux, lsof shows who holds the port, and kill sends a signal. Try a plain kill first, which asks the process to exit cleanly, and escalate to -9 only if it ignores you. On Linux, ss is a modern replacement for netstat and does not require lsof to be installed.
lsof -i :3000
# or on Linux:
ss -ltnp | grep :3000
kill 14232
# only if it will not exit:
kill -9 14232Always read the process name before killing. If it is node and the path looks like your project, that is a leftover dev server. If it is something you do not recognise, such as a database or a system service, stop and choose a different port instead. Seeing no result is also information: if the command prints nothing, the port is free now and the earlier holder has exited, so simply start the server again.
Make the port configurable
Hard-coding a port is what turns a one-off clash into a recurring problem. Reading the port from the environment lets each project, each machine and each hosting platform choose its own. Hosting panels and platforms that run Node apps normally tell your app where to listen through an environment variable, and ignoring it is a frequent reason a deployed app fails to start.
const express = require("express");
const app = express();
const port = Number(process.env.PORT) || 3000;
app.get("/", (req, res) => res.send("ok"));
const server = app.listen(port, () => {
console.log("Listening on port " + port);
});
server.on("error", (err) => {
if (err.code === "EADDRINUSE") {
console.error("Port " + port + " is busy. Set PORT to another number.");
process.exit(1);
}
throw err;
});
process.on("SIGTERM", () => server.close());
process.on("SIGINT", () => server.close(() => process.exit(0)));Run it on another port with PORT=4000 node server.js on macOS and Linux, or $env:PORT=4000; node server.js in PowerShell. The SIGINT and SIGTERM handlers matter: they close the listening socket when you press Ctrl+C or when a process manager stops the app, which prevents the zombie servers that cause the error in the first place. Framework dev servers such as Next.js accept a port flag; check the current documentation for the exact option.
Watch mode, containers and hosting panels
Tools such as nodemon restart your process whenever a file changes. If your app ignores the termination signal or takes a moment to close, the new copy can start before the old one lets go of the port. Handling SIGTERM as shown above usually resolves it. A watcher pointed at the wrong folder, such as one that includes generated or log files, can also restart the app in a loop, so check which paths it watches.
In Docker, there are two ports to keep apart: the one your app listens on inside the container and the host port you publish. An EADDRINUSE from docker run or Compose usually refers to the host side, so another container or process already holds it. Change the left number in a mapping like 3001:3000 instead of changing the app. On shared hosting and managed Node panels, the platform often sets the port or a socket path for you; read its current documentation and use the variable it provides rather than a fixed number.
Practical tip: if you cannot find a listener but the port still reports busy on Windows, check whether the number falls inside a range the system has reserved. Running netsh interface ipv4 show excludedportrange shows these ranges; picking a port outside them avoids the clash.
To confirm the fix, start the server and run the same lookup command again: it should now show exactly one listener, the process you expect. To prevent a repeat, read the port from the environment, close the server on termination signals, and stop dev servers with Ctrl+C rather than closing the terminal window.
Keep reading
- Error fixesFix 'Module not found: Can't resolve' in Next.jsThe bundler tried to follow an import and could not find a matching package or file, so the build stops. Check the exact string in the error against what is installed and what exists on disk, paying attention to filename case, extensions, path aliases and whether the import runs in the browser.
- Error fixesFix CORS Error: No Access-Control-Allow-Origin HeaderThe browser blocked a cross-origin request because the server's response did not include permission for your page's origin, in the form of an Access-Control-Allow-Origin header. The fix always lives on the server (or in a proxy you control), not in the front-end fetch call.
- Interview questions and cheat sheetsLinux Commands Cheat Sheet for Developers and ServersThis cheat sheet groups the Linux commands a developer needs on a server by the job they do: moving around, changing permissions, searching, reading logs, managing processes, checking disk and network, and connecting over SSH. It ends with the commands that destroy data and the habits that keep you safe.
- Interview questions and cheat sheetsNode.js Interview Questions and Answers for DevelopersNode.js interviews test whether you understand one idea: a single JavaScript thread that never waits, supported by an event loop and a pool of helpers. The sixteen answers below build from that idea toward streams, concurrency, Express and the failures that show up in production.
Need this built properly for your business?
CodingMarble is a remote studio in India that builds websites, apps and games on fixed packages with the scope written down before payment. Try the free tools we run, or start a project when you are ready.
- On CodingMarble
- Node.js development
- Web application development
- All guides