EADDRINUSE: address already in use
Complete troubleshooting guide for resolving port collisions and killing zombie processes on Linux, macOS, and Windows.
Error Message
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (node:net:1904:16)
at listenInCluster (node:net:1961:12)
at Server.listen (node:net:2063:7)Symptoms
- Your Next.js, Express, Fastify, or Vite development server crashes immediately upon running
pnpm devornpm start. - Terminal logs indicate code
EADDRINUSEwith a specific port number (e.g.3000,8080,5432). - The application was recently stopped with
Ctrl + Cor crashed in the background.
Why It Happens
The operating system kernel assigns network ports exclusively to one active listening socket at a time. EADDRINUSE (Error Address In Use) occurs when your Node.js process attempts to bind to a port that is already held by:
- A zombie / orphaned background process that did not exit cleanly when the previous terminal session closed.
- Another running development server or service (e.g., another Next.js project on port 3000).
- A system service already bound to that port (e.g. system PostgreSQL on port 5432).
Quick Fix (1-Liner)
Detailed Fix & Platform Instructions
Option 1: Terminate the Process Holding the Port
Linux / macOS
<Callout type="warning">
Always verify the process name from `lsof` before killing it to ensure you do not accidentally terminate a background database or unrelated developer tool.
</Callout>Windows (PowerShell / Command Prompt)
Option 2: Change Your Application Port
If you want to run multiple applications simultaneously, configure your server to use an alternative port:
Next.js
# Using CLI flag
pnpm dev -p 3001
# Or via package.json script
# "dev": "next dev -p 3001"Express / Node.js
PORT=3001 node server.jsHow to Prevent It in Node.js Applications
Ensure your server handles SIGINT (Ctrl + C) and SIGTERM signals gracefully by closing active listeners before exiting:
// server.js
const server = app.listen(3000, () => {
console.log("Server listening on port 3000");
});
function gracefulShutdown(signal) {
console.log(`Received ${signal}. Closing HTTP server...`);
server.close(() => {
console.log("HTTP server closed. Exiting process.");
process.exit(0);
});
// Force close if graceful termination hangs
setTimeout(() => {
console.error("Forced termination due to timeout.");
process.exit(1);
}, 5000);
}
process.on("SIGINT", () => gracefulShutdown("SIGINT"));
process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));Related Errors & Docs
TypeError: Cannot read properties of undefined
Fix the most common JavaScript runtime error β accessing nested properties on undefined objects and asynchronous API responses.
Blocked by CORS Policy: No 'Access-Control-Allow-Origin'
Resolve browser CORS errors in React, Next.js, Express, and Nginx reverse proxies with correct response headers.