Back to Blog
Bug Fixes•1 min read

Fix 'EADDRINUSE: address already in use' in Node.js

Scaleup Infotech Team
Scaleup Infotech Team

Custom Software & Business Automation

Node.jsExpressPorts

In this guide

A simple guide to this issue: 'EADDRINUSE: address already in use' in Node.js. Learn why it happens, what to check first, and how to fix it.

You hit Ctrl+C, restart your server, and Node refuses to boot: the port is still held by a zombie process. Here is how to free it and prevent the next one.

The Error

Error: listen EADDRINUSE: address already in use :::3000

Fix 1: Find and Kill the Process

bash
# macOS / Linux
lsof -i :3000          # find the PID using the port
kill -9 <PID>          # force-kill it

# One-liner
kill -9 $(lsof -t -i:3000)

# Windows
netstat -ano | findstr :3000
taskkill /PID <PID> /F

Fix 2: Use an Environment-Driven Port

javascript
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Listening on ${PORT}`));

Fix 3: Shut Down Gracefully

Zombie ports usually mean the old process never released the socket. Close the server on termination signals:

javascript
const server = app.listen(PORT);

process.on("SIGINT", () => {
  server.close(() => process.exit(0));
});
process.on("SIGTERM", () => {
  server.close(() => process.exit(0));
});

Using nodemon?

A crash loop can leave orphaned processes. Add a small restart delay and ensure your shutdown handlers run so the socket is released before the next boot.

Share this article:

Keep Reading

Ready to implement these ideas?

Discuss Your Project