🔴 Fix "ERR_CONNECTION_REFUSED localhost:3000" Error

Getting the "ERR_CONNECTION_REFUSED" error when trying to access localhost:3000? This guide provides quick fixes and complete troubleshooting for React, Node.js, and Express developers.

✓ React ✓ Node.js ✓ Express ✓ Next.js ✓ Gatsby ✓ Rails

🚨 What This Error Looks Like

Browser Error:
This site can't be reached
localhost refused to connect.
ERR_CONNECTION_REFUSED
Node.js/Command Line Error:
Error: connect ECONNREFUSED 127.0.0.1:3000
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)
Fetch/Axios Error:
FetchError: request to http://localhost:3000/api failed, reason: connect ECONNREFUSED 127.0.0.1:3000

⚡ Quick Fix (Most Common - 90% of Cases)

The Problem: Your development server is not running

  1. Open your terminal in your project directory
  2. Start your development server:
    • React (Create React App): npm start
    • React (Vite): npm run dev
    • Node.js/Express: npm run dev or node server.js
    • Next.js: npm run dev
  3. Wait for the success message: "Server running on port 3000" or "Compiled successfully"
  4. Refresh your browser at http://localhost:3000

🔧 Complete Troubleshooting Guide

1 Verify Server Status

First, check if your development server is actually running.

How to check:
  • Look at your terminal - you should see messages like:
    Compiled successfully!
    Local:            http://localhost:3000
    On Your Network:  http://192.168.1.5:3000
  • If your terminal is empty or shows an error, your server is NOT running
  • If you closed the terminal, the server stopped
💡 Pro Tip: Keep your development server terminal open in a separate window/tab. Never close it while working on your project.

2 Start Your Development Server

Navigate to your project directory and start the server.

Common Commands by Framework:

React (Create React App)

bash
cd your-project-folder
npm start
# or
yarn start

React (Vite)

bash
cd your-project-folder
npm run dev
# or
yarn dev

Node.js/Express

bash
cd your-project-folder
npm run dev
# or
node server.js
# or
nodemon server.js

Next.js

bash
cd your-project-folder
npm run dev
# or
yarn dev

React Development Server

bash
# Navigate to project
cd my-react-app

# Install dependencies (if first time or package.json changed)
npm install

# Start development server
npm start

# Expected output:
# Compiled successfully!
# You can now view my-react-app in the browser.
# Local: http://localhost:3000
⚠️ Common React Issues:
  • If you see "command not found: npm", install Node.js first
  • If dependencies fail, try npm install again or delete node_modules and reinstall
  • Port 3000 might be taken - React will offer to use 3001 instead

Node.js/Express Server

bash
# Navigate to project
cd my-node-app

# Install dependencies
npm install

# Start server (check your package.json for the correct script)
npm run dev

# Or directly with node:
node server.js

# Or with nodemon (auto-restart):
nodemon server.js

# Expected output:
# Server is running on port 3000
# or
# Express server listening on http://localhost:3000
💡 Check your server.js file: Make sure it has app.listen(3000, ...) or similar code that actually starts the server.

3 Check Port Number

Make sure your server is actually running on port 3000 and not a different port.

How to verify:
  • Look at your terminal output when the server starts
  • It should say "port 3000" or "localhost:3000"
  • If it says a different port (like 3001, 5000), use that URL instead
Common port configurations:
  • React CRA: Default port 3000 (auto-increments to 3001 if 3000 is busy)
  • Vite: Default port 5173
  • Express: Whatever you set in app.listen(PORT)
  • Next.js: Default port 3000

4 Check for Server Crashes

Sometimes the server starts but crashes immediately due to errors.

Look for error messages in your terminal:
  • SyntaxError - You have a code syntax error
  • MODULE_NOT_FOUND - Missing dependency, run npm install
  • EADDRINUSE - Port 3000 is already being used by another process
⚠️ If you see EADDRINUSE error:

Port 3000 is already in use by another application. You need to either:

  • Kill the process using port 3000 (see our Port Already in Use guide)
  • Or use a different port by setting the PORT environment variable

5 Firewall/Antivirus Check

Rarely, your firewall or antivirus might block local connections.

Windows users:
  1. Open Windows Defender Firewall
  2. Allow Node.js or your application through the firewall
  3. Try accessing localhost:3000 again
macOS users:
  1. System Preferences → Security & Privacy → Firewall
  2. Firewall Options → Allow Node.js or Terminal
💡 Quick test: Try using 127.0.0.1:3000 instead of localhost:3000. If 127.0.0.1 works but localhost doesn't, you may have a DNS issue.

6 Restart Everything

When in doubt, restart everything.

bash
# 1. Stop your development server
# Press Ctrl+C in the terminal running the server

# 2. Kill any lingering processes on port 3000
# macOS/Linux:
lsof -ti:3000 | xargs kill -9

# Windows (PowerShell):
Get-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess | Stop-Process -Force

# 3. Clear npm cache (if you suspect dependency issues)
npm cache clean --force

# 4. Reinstall dependencies
rm -rf node_modules package-lock.json
npm install

# 5. Start server again
npm start

🎯 Framework-Specific Solutions

React (Create React App)

Problem: Server won't start or immediately exits

bash
# Complete fix sequence:
npm install          # Ensure dependencies are installed
npm audit fix        # Fix security issues
rm -rf node_modules  # If still failing, remove modules
npm install          # Reinstall fresh
npm start            # Start development server

Node.js/Express API

Problem: Server file exists but won't listen on port

javascript
// Make sure your server.js or app.js has:
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;

// Your routes...
app.get('/', (req, res) => {
  res.send('Server is running!');
});

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

// Export for testing (optional)
module.exports = app;

Next.js

Problem: Dev server won't start

bash
# Next.js specific troubleshooting:
rm -rf .next          # Remove build cache
npm install           # Ensure dependencies
npm run dev           # Start dev server

# If still failing, check your next.config.js for errors

❌ Common Mistakes That Cause This Error

Mistake 1: Forgot to Start Server

Scenario: You opened your browser, typed localhost:3000, but never ran npm start

Solution: Always start your development server before trying to access it in the browser

Mistake 2: Closed Terminal Accidentally

Scenario: You started the server, but then closed the terminal window

Solution: Keep the server terminal open. Use a separate terminal tab/window for other commands

Mistake 3: Wrong Directory

Scenario: Running npm start in the wrong folder

Solution: Use cd to navigate to your project folder where package.json is located

Mistake 4: Server Running on Different Port

Scenario: Server is running on port 5000 but you're trying localhost:3000

Solution: Check terminal output to see which port is actually being used

🆘 Still Having Issues?

Diagnostic checklist:

If you've checked all of these and still see ERR_CONNECTION_REFUSED:
Try visiting our Interactive Diagnostic Wizard for personalized troubleshooting steps.

📝 Quick Summary

ERR_CONNECTION_REFUSED on localhost:3000 means:

The fix is usually as simple as:

  1. Open terminal in your project folder
  2. Run npm start or npm run dev
  3. Wait for "Server running" message
  4. Refresh browser at localhost:3000