Node.js Port Already in Use— Fixed [Complete Guide 2026]
⚡ Quickest Fix
Kill whatever is on the port, then restart your server:
kill -9 $(lsof -ti:3000) # replace 3000 with your portnetstat -ano | findstr :3000
taskkill /PID <PID_NUMBER> /FAfter killing — wait 2 seconds, then run npm start or npm run dev again.
What Causes Port Already in Use?
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:
- A previous npm start did not shut down properly — the server is still running in the background
- You opened a second terminal and started the server again
- nodemon crashed mid-restart and left the old process running
- macOS AirPlay Receiver is using port 5000 (common on macOS Monterey+)
- Another app — a database, nginx, or another Node server — is on the same port
- In Docker — another container is mapped to the same host port
Quick diagnostic: run lsof -i :3000 (macOS/Linux) or netstat -ano | findstr :3000 (Windows). The output shows exactly which process is holding the port.
Kill the Port — macOS / Linux
One command fixOne-liner — fastest way
# 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
# 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 14523Linux fuser command
fuser -k 3000/tcp
# Verify port is free
lsof -i :3000 # should return nothing nowAfter killing the process, wait 2–3 seconds before restarting your server. The OS needs a brief moment to fully release the port.
Kill the Port — Windows
Windows Command Prompt and PowerShellCommand Prompt
# 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 /FPowerShell — cleaner one-liner
# 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).OwningProcessIf taskkill says Access is denied
# Run PowerShell as Administrator then:
$pid = (Get-NetTCPConnection -LocalPort 3000).OwningProcess
Stop-Process -Id $pid -ForceWindows 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.
Find Exactly What Is Using the Port
Identify before killingBefore killing a process — especially on shared or production servers — it is worth knowing what you are killing.
macOS / Linux — detailed view
# 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 :3000Windows — see process name
# 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).
Change Your App Port
When you cannot or should not kill the processIf the port is being used by a critical service, the cleanest solution is changing your Node.js app to use a different port.
// 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
PORT=3001 node server.js # macOS / Linux
$env:PORT=3001; node server.js # Windows PowerShellUpdate package.json scripts
{
"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.
Auto-Kill Port on Every Dev Restart
Development workflow — never hit this againSet up your dev workflow to kill the port automatically before every restart so you never manually deal with this again.
Install kill-port
npm install --save-dev kill-portAdd to package.json scripts
{
"scripts": {
"dev": "kill-port 3000 && nodemon server.js",
"start": "kill-port 3000 && node server.js"
}
}Or add graceful shutdown to your server
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)))Docker Port Conflict
Running Node.js in DockerIn 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
# 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
# Map to different host port
docker run -p 3001:3000 my-node-app
# ^^^^ host port
# ^^^^ container port (keep this the same)docker-compose.yml
services:
app:
build: .
ports:
- "3001:3000" # changed host port from 3000 to 3001Kill Commands for Every OS — Quick Reference
Replace 3000 with your actual port
| OS | Command |
|---|---|
| macOS / Linux | kill -9 $(lsof -ti:3000) |
| Linux (fuser) | fuser -k 3000/tcp |
| Windows CMD | netstat -ano | findstr :3000 → taskkill /PID <PID> /F |
| Windows PowerShell | Stop-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess -Force |
| Docker | docker stop $(docker ps -q --filter publish=3000) |
| npm script | npx kill-port 3000 |
How to Prevent Port Already in Use
- Always use Ctrl+C to stop Node.js — never just close the terminal window
- Add kill-port to your dev script so the port clears automatically before every restart
- Use process.env.PORT — never hardcode port numbers in production
- Add SIGTERM and SIGINT handlers to release ports on clean shutdown
- Use PM2 in production — it manages process lifecycle and prevents zombie processes
- On macOS Monterey+: if you use port 5000, disable AirPlay Receiver in System Settings → Sharing
Frequently Asked Questions
Why does Node.js say port is already in use?+−
How do I kill a process on port 3000 on Mac?+−
How do I kill a process on port 3000 on Windows?+−
Port still in use after killing the process — why?+−
How do I prevent port already in use in development?+−
Node.js port already in use in Docker?+−
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