Connection Refused Error - Complete Troubleshooting Guide

Common Error Messages:
• Error: connect ECONNREFUSED 127.0.0.1:3000
• Connection refused to localhost:8080
• curl: (7) Failed to connect to localhost port 5000: Connection refused
• psql: could not connect to server: Connection refused
• Unable to connect to the server: dial tcp 127.0.0.1:8080: connect: connection refused
💡 What "Connection Refused" Means: This error occurs when your computer actively rejects the connection attempt, usually because no service is listening on the specified port.

Quick Diagnosis Steps

Step 1: Check if Service is Running

🪟 Windows
netstat -ano | findstr :PORT
Example: netstat -ano | findstr :3000
🐧 Linux / 🍎 macOS
lsof -i :PORT
Example: lsof -i :3000
netstat -tlnp | grep :PORT
Alternative method

Step 2: Test Port Connectivity

telnet localhost PORT
Example: telnet localhost 3000
curl -v http://localhost:PORT
For HTTP services

Common Causes and Solutions

1. Service Not Running

Cause: The application/server is not started

Solutions:

2. Wrong Port Number

Cause: Trying to connect to the wrong port

Solutions:

3. Service Crashed or Failed to Start

Cause: The service started but then crashed

Solutions:

4. Firewall Blocking Connection

Cause: Firewall is blocking the port

Solutions:

🪟 Windows
netsh advfirewall firewall add rule name="Allow Port 3000" dir=in action=allow protocol=TCP localport=3000
🐧 Linux
sudo ufw allow 3000 (Ubuntu)
sudo firewall-cmd --add-port=3000/tcp --permanent (CentOS/RHEL)

5. Service Binding to Wrong Interface

Cause: Service is only listening on specific network interface

Solutions:

Framework-Specific Troubleshooting

React Development Server

Spring Boot Application

Database Connections

⚠️ Prevention Tips

Related Issues