← All Articles

ECONNREFUSED: Connection Refused 127.0.0.1 — How to Fix

What Does This Error Mean?

Your code tried to connect to a server (usually localhost), but nothing is listening on that port. The OS actively refused the connection — it's not a timeout or firewall issue.

Common Causes

  • The server/database isn't running
  • Wrong port number (3000 vs 3001 vs 8080)
  • Server crashed on startup (check its logs)
  • Docker container not started or port not mapped
  • IPv4 vs IPv6 mismatch (127.0.0.1 vs ::1)

How to Fix It

1. Check if anything is listening

# Mac/Linux
lsof -i :3000
# or
netstat -tlnp | grep 3000

# Windows
netstat -ano | findstr :3000

2. Start the server

# Node.js
npm start

# PostgreSQL
sudo systemctl start postgresql

# Docker
docker-compose up -d

3. Fix IPv6 mismatch (Node.js 18+)

// If localhost resolves to ::1 but server listens on 127.0.0.1
const url = 'http://127.0.0.1:3000'  // use IP directly