Skip to content

How to Fix 'port already in use' Error (Linux, macOS, Windows)

DodaTech 1 min read

In this tutorial, you'll learn about How to Fix 'port already in use' Error (Linux, macOS, Windows). We cover key concepts, practical examples, and best practices.

The Problem

You run npm start, python app.py, or <a href="/devops/docker-compose/">docker compose</a> up and get:

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

or

Error: Port 3000 is already in use

Another process is already using that port. Here's how to free it in 10 seconds.

Quick Fix

1. Find the process using the port

# Linux / macOS
lsof -i :3000

# Windows (PowerShell)
netstat -ano | findstr :3000

Expected output (Linux/macOS):

COMMAND   PID   USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
node     4521  user   23u  IPv4  54321  0t0     TCP  *:3000 (LISTEN)

The PID is 4521 — that's what we need.

2. Kill the process

kill -9 4521

Or kill directly by port (no lookup needed):

# Linux
fuser -k 3000/tcp

Alternative: Use a Different Port

If you can't kill the process, start on another port:

# npm/node
PORT=3001 npm start

# Python/Flask
export FLASK_RUN_PORT=3001 && flask run

# Docker
docker run -p 3001:3000 my-app

Prevention

Stop your dev server properly with Ctrl+C instead of closing the terminal. Set up automatic port fallback in your app config.

Common Causes

Cause Fix
Dev server crashed in background Kill the zombie process
Another app uses the port Check with lsof and switch ports
Docker container still running docker stop <container>

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro