Error: connect ECONNREFUSED 127.0.0.1:5432
Your Node app tried to connect to a service (a database, API or dev server) and the operating system replied that nothing is listening there.
Quick checks
- Is the service running? Check with `lsof -nP -iTCP:PORT -sTCP:LISTEN`.
- Read the address in the error: `::1` vs `127.0.0.1` matters.
- In Docker, `localhost` means the container itself.
Fixes on Mac
Start the service
- Postgres, Redis, MySQL:
brew services listshows what's running;brew services start postgresql@16starts it.
- Postgres, Redis, MySQL:
Fix localhost vs ::1
- Since Node 17,
localhostcan resolve to IPv6::1first. Node 20+ then tries IPv4 too, but Node 17–19 and many database drivers don't, so a service listening only on127.0.0.1refuses the::1attempt (connect ECONNREFUSED ::1:5432). - Use
127.0.0.1in the connection string, or make the service listen on both.
- Since Node 17,
Check the port
- Compare the port in your config with what the service actually uses (LightAtom's Ports view or
lsof).
- Compare the port in your config with what the service actually uses (LightAtom's Ports view or
Fixes on Windows
Windows
netstat -ano | findstr :PORTshows whether anything listens; start the service.
Other devices
Docker
- From a container to a service on the Mac, use
host.docker.internalinstead oflocalhost. - Between containers, use the service name from Docker Compose.
- From a container to a service on the Mac, use
Still not working?
If the service is running and listening and you still get ECONNREFUSED, a firewall rule may reject the connection, or the service listens on a different interface (for example only a Docker network).
See what’s happening
LightAtom's Ports view shows every listening port on your Mac, its process, and whether it listens on localhost only, a specific address or all interfaces.
Frequently asked questions
What does ECONNREFUSED mean in Node.js?
The connection was actively refused: the address and port have no listening process, or a firewall rejected it.
Why do I get ECONNREFUSED ::1?
localhost resolved to IPv6 ::1 but your service listens only on IPv4 127.0.0.1. Use 127.0.0.1 or configure the service to listen on ::1 too.
Why does localhost not work inside Docker?
Inside a container, localhost is the container. Use host.docker.internal to reach your Mac, or the other container's service name.