ECONNREFUSED Node.js Origin: Application & API Last updated 12 Oct 2026

Error: connect ECONNREFUSED 127.0.0.1:5432

Nothing is listening at that host:port — the target service is down or you’re connecting to the wrong address.

Exact message you may see connect ECONNREFUSEDConnection refused
Seen on: Node.js Docker

Meaning

The OS actively refused the TCP connection. Inside Docker, 127.0.0.1 refers to the container itself, not your host or other containers — a very common cause.

Common causes

  • Target service (DB, Redis, API) not running
  • Wrong port
  • Using localhost inside a container instead of the service name
  • Service listening only on 127.0.0.1 while you connect from elsewhere
  • Node 17+ resolving localhost to IPv6 ::1 while the service listens on IPv4 only

⚡ Quick fix

  1. Start the target service and check its port
  2. In Docker Compose, use the service name as host
  3. Use 127.0.0.1 instead of localhost (IPv6 issue)
  4. Make the service listen on 0.0.0.0 if accessed remotely

Detailed fix by platform

Docker

  1. From a container to the host machine: use host.docker.internal (Docker Desktop) or add extra_hosts: ["host.docker.internal:host-gateway"].

Node.js

  1. Retry on startup — databases often accept connections a few seconds after the app container starts.

How to diagnose

  1. Target — Which host:port in the message?
  2. Service — Is it running and listening there?
  3. Network — Same container/network/IP version?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

0x80070035 — 0x80070035: The network path was not found (System error 53) (Windows)0x800700350x80072EE7 — Error 0x80072EE7 (Windows Update / Microsoft Store: server name could not be resolved) (Windows)0x80072EE70x8024402C — Windows Update error 0x8024402C (cannot connect to update server) (Windows)0x8024402C14 UNAVAILABLE — gRPC Error: 14 UNAVAILABLE: No connection established / failed to connect to all addresses (API)14 UNAVAILABLE2002 — MySQL ERROR 2002 (HY000): Can't connect to local MySQL server through socket (MySQL)2002502 — HTTP 502 Bad Gateway (HTTP)502511 — HTTP 511 Network Authentication Required (HTTP)511actively refused it — HttpRequestException: No connection could be made because the target machine actively refused it (localhost:5001) (.NET)actively refused itECONNREFU…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.