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.
connect ECONNREFUSEDConnection refused 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
localhostto IPv6::1while the service listens on IPv4 only
⚡ Quick fix
- Start the target service and check its port
- In Docker Compose, use the service name as host
- Use
127.0.0.1instead oflocalhost(IPv6 issue) - Make the service listen on
0.0.0.0if accessed remotely
Detailed fix by platform
Docker
- From a container to the host machine: use
host.docker.internal(Docker Desktop) or addextra_hosts: ["host.docker.internal:host-gateway"].
Node.js
- Retry on startup — databases often accept connections a few seconds after the app container starts.
How to diagnose
- Target — Which host:port in the message?
- Service — Is it running and listening there?
- 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:
Similar errors
Most viewed in Node.js
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 12 Oct 2026