Skip to content
RU

connect ECONNREFUSED 127.0.0.1:3000 — Why Nothing Is Listening and How to Fix It

What it means: The target host answered your connection attempt with a refusal: no process listens on that address and port.

  1. Start the service and check its port
  2. Compare the address in the error with ss -ltn
  3. Try 127.0.0.1 instead of localhost
  4. In Docker, use the service name

Test your URL now

Pings your host from our server, so you see whether it answers from outside your network.

Check your host & ports →

What ECONNREFUSED means

ECONNREFUSED is the system error «Connection refused». The Linux connect(2) page says a connect() on a stream socket «found no one listening on the remote address», and the Node.js docs add: «This usually results from trying to connect to a service that is inactive on the foreign host.» In Node.js it looks like this:

Error: connect ECONNREFUSED 127.0.0.1:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net)  {
  errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 5432 }

The address and port in the message are the most useful part: they show where the client actually tried to connect, which is often not where you think. The host itself is up, since something answered with a refusal; that is what separates this error from ETIMEDOUT, where nothing answers at all. curl reports the same case as exit code 7, «Failed to connect() to host or proxy», and Chrome as ERR_CONNECTION_REFUSED.

Causes

CauseHow to recognise itFix
Service not running or crashedNo process on the port in ss -ltnStart it; read its logs for why it exited
Wrong portThe service listens on another portFix the port in config or environment
Listening on 127.0.0.1 onlyWorks on the server, refused from other machinesBind to 0.0.0.0 or the interface address
localhost resolves to ::1Error shows ::1:3000; server listens on IPv4 onlyUse 127.0.0.1 or listen on both families
localhost inside a containerWorks on the host, refused inside DockerConnect to the other container by its service name
Firewall REJECT ruleRefused instantly although the service listensAllow the port in the firewall
Server not ready yetFails right after startup, works seconds laterWait for a health check before connecting

localhost, ::1 and Node.js 17+

A common surprise after a Node.js upgrade: connect ECONNREFUSED ::1:3000 while the server is clearly running. In Node.js 17.0.0 the default of dns.lookup()'s verbatim option became true, so addresses are returned in the order the resolver gives them instead of IPv4 first (Node.js dns docs). On many systems localhost resolves to ::1 first, and a server bound only to 127.0.0.1 refuses the IPv6 attempt.

Node.js 20.0.0 and 18.18.0 made autoSelectFamily default to true for net.connect(), which tries the other address family when the first fails (net docs), so the problem shows up less often, but tools and libraries with their own connect logic still hit it. Fixes, in order of preference:

  • Connect to 127.0.0.1 explicitly instead of localhost.
  • Make the server listen on both families (server.listen(3000, '::') on a dual-stack host).
  • As a last resort, restore the old order with --dns-result-order=ipv4first or dns.setDefaultResultOrder('ipv4first').

Inside Docker and docker compose

Inside a container, localhost is the container itself, not your laptop and not the database container. An app container that connects to localhost:5432 gets ECONNREFUSED even though Postgres runs in the next container. On a user-defined network, containers reach each other by name: Docker's bridge network docs state that «User-defined bridges provide automatic DNS resolution between containers», while on the default bridge containers can only reach each other by IP address. In compose, every service gets a name on the project network:

services:
  app:
    environment:
      DATABASE_URL: postgres://app:secret@db:5432/app   # not localhost
  db:
    image: postgres:16

Also check the server inside the container: a dev server bound to 127.0.0.1 inside the container refuses connections from the published port. Bind it to 0.0.0.0.

How to fix it

  1. Read the address and port in the error and test exactly that from the same machine or container:
    nc -vz 127.0.0.1 5432
    curl -v http://127.0.0.1:3000/
  2. See what is listening on the target host:
    ss -ltnp | grep -E ':(3000|5432)\b'
    # LISTEN 0 511 127.0.0.1:3000 0.0.0.0:* users:(("node",pid=812,fd=21))
    A listener on 127.0.0.1 only accepts local connections; a missing line means the service is not running.
  3. Check the service and its logs: systemctl status app, journalctl -u app -n 50, docker compose ps, docker compose logs db.
  4. Check the firewall if the port listens but remote clients are refused: iptables -S | grep -i reject or nft list ruleset.
  5. Wait for readiness in startup scripts. Retry the connection with backoff, or use a health check, instead of failing on the first refusal while a database is still starting.

Browser view of the same problem: ERR_CONNECTION_REFUSED.

How to confirm the fix

nc -vz api.example.com 443
# Connection to api.example.com 443 port [tcp/https] succeeded!

Then rerun the client: the error should be gone, or turn into an application-level response. For a public host, the ping and port checker shows whether the port answers from outside your network.

Related errors

ICMP PingHost availability and latency
Port ScannerOpen TCP port detection
LatencyResponse time in milliseconds
Packet LossPercentage of dropped packets

Why teams trust us

ICMP+TCP
check protocols
14
key ports scanned
3,184
checks in 30 days
3
regions

How it works

1

Enter IP or domain

2

ICMP packets sent

3

Latency & packet loss shown

How Do Ping and Port Scanning Work?

Ping sends ICMP packets to a host and measures response time. Port scanning checks which TCP ports are open and accepting connections — helping diagnose serviceavailability issues.

Configurable Ping

Choose packet count (3, 4, 6, 10). Stats: min/avg/max latency and packet loss.

Common Port Scanner

Check 14 key ports: HTTP, HTTPS, SSH, FTP, SMTP, MySQL, PostgreSQL, and more.

Cloud-Based Check

Testing from our server — see site availability from outside, not just your local network.

Uptime Monitoring

Need constant monitoring? Create a monitor — checks every minute with notifications.

Who uses this

DevOps

availability diagnosis

Network engineers

TCP port scanning

Developers

connection debugging

SRE

basic health check

Common Mistakes

ICMP blocked = server is downMany servers block ICMP. Ping fails but site works — check ports instead.
High ping = server problemLatency depends on geography. 150ms between continents is normal, not an error.
Closed ports — cause for alarmClosed ports of unused services are good. Unnecessary open ports are a risk.
One check = sufficientNetworks are unstable. A single timeout ≠ a problem. Check multiple times or set up monitoring.

Best Practices

Combine ping and port checksPing shows host availability, ports show specific service availability. Use both.
Check from different locationsThe problem may be local. A cloud test shows the real picture.
Close unused portsEvery open port is a potential attack vector. Keep only necessary ports open.
Set up monitoringManual checks do not scale. Set up automated monitoring with notifications.

Get more with a free account

Ping check history, host availability monitoring and downtime alerts.

Sign up free

Learn more

Sources

Frequently Asked Questions

Why do I get connect ECONNREFUSED ::1 after upgrading Node.js?

Since Node.js 17, localhost may resolve to the IPv6 address ::1 first. A server listening on 127.0.0.1 only refuses it. Use 127.0.0.1 or listen on both families.

Why does localhost not work inside a Docker container?

Inside a container localhost is the container itself. Connect to the other container by its service name on a shared user-defined network.

What is the difference between ECONNREFUSED and ETIMEDOUT?

Refused means the host answered and nothing listened on the port. Timed out means nothing answered at all, typically a firewall that silently drops packets.

Is ECONNREFUSED a firewall problem?

Sometimes. A REJECT rule produces an immediate refusal, but most cases are a stopped service, a wrong port or a server listening on 127.0.0.1 only.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.