localhost Refused to Connect: Find the Cause in Minutes
When localhost refuses to connect, your computer is reachable but no program is accepting connections on that address and port. Most often the dev server is not running or printed another port. Next suspects are a server bound to ::1 while you asked for 127.0.0.1, a missing Docker port mapping, or WSL networking.
| What you see | Likely cause | Check |
|---|---|---|
| Refused right after starting | Server crashed on startup | First error in the terminal |
| localhost fails, 127.0.0.1 works | Server listens on IPv4 only | Use 127.0.0.1 or bind to :: |
| 127.0.0.1 fails, localhost works | Server listens on ::1 only | Bind to 0.0.0.0 or :: |
| Works in container, not in browser | Port not published | docker ps PORTS column |
| ECONNREFUSED ::1 from Node | Node 17+ tried IPv6 first | Use 127.0.0.1 in the client URL |
Updated
A refusal is fast and definite: the operating system answered on behalf of the port and said nobody is home. That rules out DNS and the internet entirely, so the search is small. Either the server is not there, it is on another port, or it is listening on a different loopback address from the one your client used.
Find what is listening, and on which address
List the listener for one port
Look at the address column: 127.0.0.1, [::1], * or 0.0.0.0 tells you which loopback works.
# Mac / Linux
lsof -nP -iTCP:3000 -sTCP:LISTEN
# Linux alternative
ss -ltnp | grep 3000
# Windows
netstat -ano | findstr :3000Make a Node server accept IPv4 and IPv6
Listening on :: accepts both families on most systems, which ends the localhost versus 127.0.0.1 mismatch.
import http from "node:http";
http
.createServer((req, res) => res.end("ok"))
.listen(3000, "::", () => console.log("http://localhost:3000"));
Docker and port publishing
docker run -p 8080:80 sends host port 8080 to container port 80. The left side is what you type in the browser. In docker compose, the same rule applies under ports, and the PORTS column of docker ps shows whether the mapping exists at all.
If the mapping is there but you are still refused, the app inside is probably bound to 127.0.0.1 within the container. Change its host setting to 0.0.0.0.
Port pages for specific tools
Each common port has its own quirks, such as AirPlay holding 5000 on a Mac or Vite moving from 5173 to 5174. If you would rather publish a business site than debug a local server, We.Inc hosts the preview for you and there is no loopback address involved.
How it works
- Look at the terminal that started the server and confirm it is still running.
- Copy the exact URL it printed, including the port, into the browser.
- List listening ports to see which address and port the process really holds.
- Match the client to that address, or change the server to listen on all interfaces.
Tips
- Since Node 17, dns lookups return addresses in the order the system gives, so localhost can resolve to ::1 first. A client calling localhost then fails against a server bound only to 127.0.0.1.
- Inside a Docker container, localhost is the container. To reach a service on the host from a container use host.docker.internal.
- A server inside a container must listen on 0.0.0.0, not 127.0.0.1, or a published port still gets refused.
- On Windows with WSL 2, a server that binds only to the Linux loopback may not show up on Windows localhost; bind to 0.0.0.0 or enable mirrored networking.
Frequently asked questions
Why does localhost refuse to connect when my server is running?
It is usually on a different port or address than the one you opened. Compare the port in the address bar with the server log, and try both 127.0.0.1 and [::1] to see which loopback it uses.
What does 127.0.0.1 refused to connect mean?
Nothing is listening on that port over IPv4. The server may be stopped, using another port, or bound only to the IPv6 loopback ::1. Start it with a host of 0.0.0.0 to cover IPv4.
How do I fix ECONNREFUSED ::1 in Node?
Your client resolved localhost to the IPv6 address while the server listens on IPv4. Point the client at 127.0.0.1, or make the server listen on :: so it accepts both.
Can a firewall cause localhost refused to connect?
Rarely for plain loopback, since most firewalls trust it. Security suites and some corporate endpoint tools do filter it, though. If everything else checks out, pause that software briefly to test.
Related: What is localhost, This site can't be reached, localhost:3000, localhost:5000.
Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.
More in Guides
- Location Pages SEO: Real Pages for Real Places
- Logo Size for a Website: Every Size You Need
- How to Make a Website with HTML and CSS
- Markdown Cheat Sheet
- Microsoft Teams Webhook: How to Post Messages in 2026
- Migrating Off Drupal Multisite: Choosing a Path After Drupal 7 and Moving Sites in Order | How-to Guide
- Migrating Off WordPress Multisite: Inventory, Export, Rebuild and Redirect Without Losing Traffic | How-to Guide
- Mobile-First Web Design: What It Means and How to Do It | How-to Guide
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App