Port Already in Use - Complete Troubleshooting Guide

Common Error Messages:
• Error: listen EADDRINUSE: address already in use :::3000
• Port 8080 is already in use
• Address already in use (OS Error: Address already in use, errno = 98)
• Web server failed to start. Port 5000 was already in use
• java.net.BindException: Address already in use: JVM_Bind
💡 Quick Fix: Most "port already in use" errors can be solved by either killing the process using the port, or changing your application to use a different port.

Step-by-Step Solution

🪟 Windows

1. Find what's using the port

netstat -ano | findstr :PORT_NUMBER
Example: netstat -ano | findstr :3000

2. Kill the process

taskkill /PID PID_NUMBER /F
Example: taskkill /PID 1234 /F

Alternative: Find and kill in one command

for /f "tokens=5" %a in ('netstat -aon ^| findstr :3000') do taskkill /PID %a /F
🐧 Linux

1. Find what's using the port

sudo lsof -i :PORT_NUMBER
Example: sudo lsof -i :3000
sudo netstat -tulpn | grep :PORT_NUMBER
Alternative method

2. Kill the process

sudo kill -9 PID_NUMBER
Example: sudo kill -9 1234

One-liner solution

sudo kill -9 $(sudo lsof -t -i:3000)
🍎 macOS

1. Find what's using the port

lsof -i :PORT_NUMBER
Example: lsof -i :3000

2. Kill the process

kill -9 PID_NUMBER
Example: kill -9 1234

One-liner solution

kill -9 $(lsof -t -i:3000)
⚠️ macOS Monterey Note: AirPlay uses port 5000 by default. To disable it, go to System Preferences > Sharing > AirPlay Receiver and turn it off.

Framework-Specific Solutions

Node.js / Express

Change the port in your application:

const PORT = process.env.PORT || 3001;
app.listen(PORT, () => console.log(`Server running on port ${PORT}`));

Or set environment variable:

PORT=3001 npm start

React (Create React App)

React will automatically suggest the next available port, or you can specify:

PORT=3001 npm start (Mac/Linux)
set PORT=3001 && npm start (Windows)

Spring Boot

Change port in application.properties:

server.port=8081

Or use command line:

java -jar app.jar --server.port=8081

Django

Specify a different port when running:

python manage.py runserver 8001

Flask

Change the port in your app:

app.run(port=5001)

Or use command line:

flask run --port 5001

Quick Reference: Common Development Ports

Port Common Use Alternative Ports
3000 React, Express, Rails 3001, 3002, 3003
8080 Spring Boot, Tomcat 8081, 8082, 8090
5000 Flask, .NET Core 5001, 5002, 5003
8000 Django, PHP 8001, 8002, 8003
4200 Angular 4201, 4202, 4203
5173 Vite.js 5174, 5175, 5176

⚠️ Important Notes

💡 Prevention Tips

Related Issues