Connection Refused Error
Fix 'ECONNREFUSED' and 'Connection refused' errors when connecting to databases, APIs, or other services.
What Does This Error Mean?
The 'Connection refused' error (ECONNREFUSED) means the operating system actively rejected a connection attempt to a specific IP address and port. This typically happens when no service is listening on that port, or a firewall is blocking the connection.
Common Causes
The target service (database, API, server) is not running
Wrong port number in the connection string
Service is listening on a different network interface (e.g., 127.0.0.1 instead of 0.0.0.0)
Firewall rules are blocking the connection
Docker container port is not mapped to the host
Service crashed or was stopped and not restarted
How to Fix It
Check if the service is running
Verify the service is running and listening on the expected port.
# Check if process is listening on port netstat -an | findstr :5432 # or netstat -tulpn | grep 5432 # Check if the service is running systemctl status postgresql # or pg_isready
Verify the connection string
Check that the host, port, and other connection parameters are correct.
# Example connection strings postgresql://user:pass@localhost:5432/mydb # PostgreSQL mysql://user:pass@localhost:3306/mydb # MySQL mongodb://localhost:27017/mydb # MongoDB redis://localhost:6379 # Redis
Test connectivity
Use telnet or nc to test if the port is reachable.
# Test TCP connection telnet localhost 5432 # or nc -zv localhost 5432 # Test from another machine nc -zv server-hostname 5432
Related Tools
Use these tools to debug and fix this error:
Related Errors
Other common errors in this category:
SSL Certificate Expired Error
Fix 'NET::ERR_CERT_DATE_INVALID' and 'SSL certificate expired' errors in browsers. Learn how to update and manage SSL/TLS certificates.
DNS Not Resolved Error
Fix 'DNS not resolved' or 'net::ERR_NAME_NOT_RESOLVED' errors. Learn how DNS resolution works and how to fix domain name lookup failures.
ERR_CONNECTION_RESET Error
Fix 'ERR_CONNECTION_RESET' or 'net::ERR_CONNECTION_RESET' errors in Chrome and other browsers. Learn why TCP connections are reset and how to fix them.
ERR_SSL_PROTOCOL_ERROR Error
Fix 'ERR_SSL_PROTOCOL_ERROR' errors in Chrome and browsers. Learn how SSL/TLS handshake failures happen and how to fix protocol mismatches.
Frequently Asked Questions
What is the difference between connection refused and timeout?
Connection refused (ECONNREFUSED) means the server actively rejected the connection — the port is reachable but nothing is listening. Timeout (ETIMEDOUT) means the server did not respond at all, often due to firewall or network issues.
Why does localhost work but 127.0.0.1 doesn't?
Some applications bind to IPv6 (::1) by default. Use 'localhost' which resolves to both IPv4 and IPv6, or check if the service is listening on IPv6 only with `netstat -an`.