Node.jsExpressError Fix2026 Updated

Node.js Port Already in Use— Fixed [Complete Guide 2026]

January 20265 min readNode.js · All OS

⚡ Quickest Fix

Kill whatever is on the port, then restart your server:

macOS / Linux — one command
kill -9 $(lsof -ti:3000)   # replace 3000 with your port
Windows PowerShell
netstat -ano | findstr :3000
taskkill /PID <PID_NUMBER> /F

After killing — wait 2 seconds, then run npm start or npm run dev again.

What Causes Port Already in Use?

Terminal Error
Error: listen EADDRINUSE: address already in use :::3000
    at Server.setupListenHandle [as _listen2] (net.js:1318:16)
    at listenInCluster (net.js:1366:12)
    at Server.listen (net.js:1452:7)

Your Node.js app tried to bind to a port that another process is already listening on. The OS only allows one process per port at a time. This is almost always caused by one of these:

Quick diagnostic: run lsof -i :3000 (macOS/Linux) or netstat -ano | findstr :3000 (Windows). The output shows exactly which process is holding the port.

1

Kill the Port — macOS / Linux

One command fix
30 sec

One-liner — fastest way

terminal
# Kill whatever is on port 3000
kill -9 $(lsof -ti:3000)

# Other common ports
kill -9 $(lsof -ti:8080)
kill -9 $(lsof -ti:5000)
kill -9 $(lsof -ti:4000)

Step by step — see what you are killing first

terminal
# Step 1: Find what is on the port
lsof -i :3000
# Shows: COMMAND, PID, USER, TYPE, NODE, NAME
# Example output:
# node    14523  john   IPv6  TCP  *:3000 (LISTEN)

# Step 2: Kill using the PID
kill -9 14523

Linux fuser command

terminal
fuser -k 3000/tcp

# Verify port is free
lsof -i :3000   # should return nothing now

After killing the process, wait 2–3 seconds before restarting your server. The OS needs a brief moment to fully release the port.

2

Kill the Port — Windows

Windows Command Prompt and PowerShell
1 min

Command Prompt

cmd
# Step 1: Find PID on port 3000
netstat -ano | findstr :3000
# Example output:
# TCP    0.0.0.0:3000   0.0.0.0:0   LISTENING   14523
#                                              ^^^^^ this is the PID

# Step 2: Kill it
taskkill /PID 14523 /F

PowerShell — cleaner one-liner

PowerShell
# Find and kill in two steps
$pid = (Get-NetTCPConnection -LocalPort 3000).OwningProcess
Stop-Process -Id $pid -Force

# Or check what process it is first
Get-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess

If taskkill says Access is denied

PowerShell (run as Administrator)
# Run PowerShell as Administrator then:
$pid = (Get-NetTCPConnection -LocalPort 3000).OwningProcess
Stop-Process -Id $pid -Force

Windows sometimes keeps ports in TIME_WAIT state for ~4 minutes after a process is killed. If the port seems stuck, either wait a few minutes or switch to port 3001 temporarily.

3

Find Exactly What Is Using the Port

Identify before killing
1 min

Before killing a process — especially on shared or production servers — it is worth knowing what you are killing.

macOS / Linux — detailed view

terminal
# Full details of process on port 3000
lsof -i :3000
# Columns: COMMAND, PID, USER, FD, TYPE, DEVICE, SIZE, NODE, NAME

# See ALL listening ports
lsof -i -P -n | grep LISTEN

# Linux — modern ss command
ss -tulpn | grep :3000

# Linux — classic netstat
netstat -tlnp | grep :3000

Windows — see process name

cmd
# Find PID
netstat -ano | findstr :3000

# See what program owns the PID
tasklist /FI "PID eq 14523"

If the COMMAND column shows 'node' — safe to kill. If it shows 'nginx', 'postgres', 'mongod', or another service — change your Node.js port instead (Fix 4).

4

Change Your App Port

When you cannot or should not kill the process
1 min

If the port is being used by a critical service, the cleanest solution is changing your Node.js app to use a different port.

server.js
// Use environment variable for flexible port config
const PORT = process.env.PORT || 3001   // changed from 3000

app.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`)
})

Run on different port without changing code

terminal
PORT=3001 node server.js       # macOS / Linux
$env:PORT=3001; node server.js  # Windows PowerShell

Update package.json scripts

package.json
{
  "scripts": {
    "dev": "PORT=3001 nodemon server.js",
    "start": "node server.js"
  }
}

Always use process.env.PORT — hosting platforms like Heroku, Railway, and Render set this automatically in production. Never hardcode a port number in production code.

5

Auto-Kill Port on Every Dev Restart

Development workflow — never hit this again
2 min

Set up your dev workflow to kill the port automatically before every restart so you never manually deal with this again.

Install kill-port

terminal
npm install --save-dev kill-port

Add to package.json scripts

package.json
{
  "scripts": {
    "dev": "kill-port 3000 && nodemon server.js",
    "start": "kill-port 3000 && node server.js"
  }
}

Or add graceful shutdown to your server

server.js
const server = app.listen(PORT, () => {
  console.log(`Server on port ${PORT}`)
})

// Clean up on exit — releases the port properly
process.on('SIGTERM', () => server.close(() => process.exit(0)))
process.on('SIGINT', () => server.close(() => process.exit(0)))
6

Docker Port Conflict

Running Node.js in Docker
3 min

In Docker environments, port already in use usually means another container is mapped to the same host port — not a process on the host machine.

Find the conflicting container

terminal
# List all running containers and their port mappings
docker ps
# Look for a container showing 0.0.0.0:3000->3000/tcp

# Stop the conflicting container
docker stop <container_id>

Change the host port mapping

terminal
# Map to different host port
docker run -p 3001:3000 my-node-app
#               ^^^^  host port
#                    ^^^^ container port (keep this the same)

docker-compose.yml

docker-compose.yml
services:
  app:
    build: .
    ports:
      - "3001:3000"   # changed host port from 3000 to 3001

Kill Commands for Every OS — Quick Reference

Replace 3000 with your actual port

OSCommand
macOS / Linuxkill -9 $(lsof -ti:3000)
Linux (fuser)fuser -k 3000/tcp
Windows CMDnetstat -ano | findstr :3000 → taskkill /PID <PID> /F
Windows PowerShellStop-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess -Force
Dockerdocker stop $(docker ps -q --filter publish=3000)
npm scriptnpx kill-port 3000

How to Prevent Port Already in Use

Frequently Asked Questions

Why does Node.js say port is already in use?+
Another process is listening on the same port. Either a previous Node.js server did not shut down cleanly, another application is using the same port, or you started your server twice in different terminals.
How do I kill a process on port 3000 on Mac?+
Run kill -9 $(lsof -ti:3000) in your terminal. This finds the process ID using port 3000 and kills it in one command. Replace 3000 with your actual port.
How do I kill a process on port 3000 on Windows?+
Run: netstat -ano | findstr :3000 to find the PID, then: taskkill /PID <PID> /F to kill it. Replace <PID> with the number from the first command.
Port still in use after killing the process — why?+
Windows has a TCP TIME_WAIT period where the OS keeps a port reserved for ~4 minutes after a process releases it. Either wait a few minutes or use a different port temporarily.
How do I prevent port already in use in development?+
Use the kill-port npm package in your dev script: 'dev': 'kill-port 3000 && nodemon server.js'. Or always stop your server with Ctrl+C before restarting.
Node.js port already in use in Docker?+
Another container is bound to the same host port. Run docker ps to list containers and docker stop <id> to stop the conflicting one. Or change your Docker port mapping: -p 3001:3000.

Need Expert Help?

We Build Production-Grade Node.js Apps

Softplix is a full-stack development agency. Dealing with Node.js infrastructure issues in production? We can help you build something stable.

Talk to an Engineer