search
Javascript

Fix: Error when starting dev server: port already in use error

Quick fix for 'Error when starting dev server: port already in use' error. Learn how to resolve port conflicts in JavaScript development servers.

person By Gautam Sharma
calendar_today January 8, 2026
schedule 2 min read
JavaScript Development Server Port Error Fix Server Configuration

The ‘Error when starting dev server: port already in use’ error occurs when trying to start a development server on a port that’s already being used by another process or server instance.


How the Error Happens

❌ Error Scenario:

# ❌ This causes the error
npm run dev
# Error: Port 3000 is already in use

✅ Quick Fix - Resolve Port Conflicts

Solution 1: Find and Kill Process Using the Port

# ✅ Find process using port 3000 (Linux/Mac)
lsof -i :3000

# ✅ Kill the process
kill -9 PID  # Replace PID with actual process ID

# ✅ On Windows
netstat -ano | findstr :3000
taskkill /PID PID /F  # Replace PID with actual process ID

Solution 2: Use Different Port

# ✅ Start server on different port
npm run dev -- --port 3001

# ✅ For Next.js
PORT=3001 npm run dev

# ✅ For Vite
vite --port 3001

# ✅ For React
PORT=3001 npm start

Solution 3: Configure Port in Environment

// ✅ In package.json scripts
{
  "scripts": {
    "dev": "vite --port 3002",
    "dev:alt": "vite --port 4000"
  }
}

Solution 4: Auto-assign Available Port

// ✅ For custom servers, auto-assign port
const express = require('express');
const app = express();

const PORT = process.env.PORT || 3000;

app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
}).on('error', (err) => {
  if (err.code === 'EADDRINUSE') {
    console.log(`Port ${PORT} is busy, trying ${PORT + 1}`);
    app.listen(PORT + 1);
  }
});
Gautam Sharma

About Gautam Sharma

Full-stack developer and tech blogger sharing coding tutorials and best practices

Related Articles

Javascript

Fix: Cross-origin request blocked in Vite dev server error

Quick fix for 'Cross-origin request blocked in Vite dev server' error. Learn how to configure CORS and proxy settings in Vite.

January 8, 2026
Javascript

How to Resolve Dynamic import callback was not specified error

Quick fix for 'Dynamic import callback was not specified' error. Learn how to properly handle dynamic imports in JavaScript applications.

January 8, 2026
Javascript

Fix: ESM packages need to be imported error

Quick fix for 'ESM packages need to be imported' error. Learn how to properly import ES modules in Node.js and JavaScript environments.

January 10, 2026