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.
This site can't be reached localhost refused to connect. ERR_CONNECTION_REFUSED
Error: connect ECONNREFUSED 127.0.0.1:3000
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)
FetchError: request to http://localhost:3000/api failed, reason: connect ECONNREFUSED 127.0.0.1:3000
The Problem: Your development server is not running
npm startnpm run devnpm run dev or node server.jsnpm run devFirst, check if your development server is actually running.
How to check:Compiled successfully! Local: http://localhost:3000 On Your Network: http://192.168.1.5:3000
Navigate to your project directory and start the server.
cd your-project-folder npm start # or yarn start
cd your-project-folder npm run dev # or yarn dev
cd your-project-folder npm run dev # or node server.js # or nodemon server.js
cd your-project-folder npm run dev # or yarn dev
# 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
npm install again or delete node_modules and reinstall# 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
app.listen(3000, ...) or similar code that actually starts the server.
Make sure your server is actually running on port 3000 and not a different port.
How to verify:app.listen(PORT)Sometimes the server starts but crashes immediately due to errors.
Look for error messages in your terminal:SyntaxError - You have a code syntax errorMODULE_NOT_FOUND - Missing dependency, run npm installEADDRINUSE - Port 3000 is already being used by another processPort 3000 is already in use by another application. You need to either:
Rarely, your firewall or antivirus might block local connections.
Windows users:When in doubt, restart everything.
# 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
Problem: Server won't start or immediately exits
# 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
Problem: Server file exists but won't listen on port
// 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;
Problem: Dev server won't start
# 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
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
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
Scenario: Running npm start in the wrong folder
Solution: Use cd to navigate to your project folder where package.json is located
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
Diagnostic checklist:
node --version)npm --version)ls package.json)ls node_modules should show many folders)
If you've checked all of these and still see ERR_CONNECTION_REFUSED:
Try visiting our Interactive Diagnostic Wizard for personalized troubleshooting steps.
ERR_CONNECTION_REFUSED on localhost:3000 means:
The fix is usually as simple as:
npm start or npm run dev