Error: connect ECONNREFUSED 127.0.0.1:5432
Node can’t connect to the server at that address. The service isn’t running or the address is wrong.
Fix 1: Check if the service is running
# For a database
sudo systemctl status [postgresql](/blog/what-is-postgresql/)
# For any port
lsof -i :5432
Fix 2: Check the connection string
// ❌ Wrong port or host
const client = new Client({ host: 'localhost', port: 5433 });
// ✅ Correct
const client = new Client({ host: 'localhost', port: 5432 });
Fix 3: Docker — use the service name, not localhost
// ❌ Inside Docker, localhost is the container itself
const client = new Client({ host: 'localhost' });
// ✅ Use the [Docker Compose](/blog/docker-compose-validator/) service name
const client = new Client({ host: 'db' });