“localhost refused to connect” means your browser reached your own PC, but nothing accepted the connection on that port: the server is not running, it is listening on a different port, or it is listening on a different address, often 127.0.0.1 when the browser tried ::1. The fix is to find out what, if anything, is listening on the port, and on which address. Port Detective, a Windows app from Automata Labs, shows you the process that owns a port the moment you type the number, so you can tell those cases apart without reading netstat output by hand.
This guide explains what the error means, a two-minute check, and the IPv4 versus IPv6 trap that catches many Node.js and Vite setups.
Type the port and see which process is listening, with its PID and connection state.
Get it from Microsoft
What does “refused to connect” actually mean?
When a browser connects to a port where nothing is listening, Windows answers with a refusal right away. Chromium, the engine in Chrome and Edge, reports this as ERR_CONNECTION_REFUSED. Its network error list defines that error, number -102, as “A connection attempt was refused.” The page you see says the host “refused to connect.”
At the Windows level it is Winsock error 10061, WSAECONNREFUSED. Microsoft’s Windows Sockets error codes describe it as: “No connection could be made because the target computer actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host,” which Microsoft explains as one with no server application running.
That points away from some popular guesses. A refusal is an immediate answer, not a timeout. The page never loading, or loading forever, is a different symptom.
| Symptom | Likely meaning |
|---|---|
| ”refused to connect”, ERR_CONNECTION_REFUSED | Nothing accepted the connection on that address and port |
| Spinner, then ERR_CONNECTION_TIMED_OUT | Packets are not getting an answer; often a firewall or a remote host |
| ”This site can’t be reached” with a DNS error | The name did not resolve |
| The wrong app’s page loads | Something else is listening on that port |
| EADDRINUSE when you start the server | Something already holds the port |
The last row is the opposite problem: the port is busy, not empty. Our guide to fixing EADDRINUSE on Windows covers it.
How do you check what is listening on the port?
Take two minutes before you change any config. Replace 5173 with your port.
1. Is anything listening at all? In PowerShell:
Get-NetTCPConnection -LocalPort 5173 -State Listen -ErrorAction SilentlyContinue |
Select-Object LocalAddress, LocalPort, OwningProcess
Or with the classic tool:
netstat -ano | findstr ":5173"
No output means nothing is listening on that port. The server did not start, crashed, or is using another port. Read its console output: dev servers print the address they bound to.
2. Which address is it on? Look at the local address column:
| Local address | Listening on | Reachable as |
|---|---|---|
127.0.0.1 | IPv4 loopback only | http://127.0.0.1:5173 |
::1 | IPv6 loopback only | http://[::1]:5173 |
0.0.0.0 | Every IPv4 address | 127.0.0.1 and your LAN IPv4 address |
:: | Every IPv6 address, and on many systems IPv4 too | Depends on the dual-stack setting |
3. Try both loopback addresses directly. Windows 10 and 11 include curl:
curl.exe -I http://127.0.0.1:5173
curl.exe -I "http://[::1]:5173"
If one works and the other is refused, you have found the cause.
Why does localhost fail when 127.0.0.1 works?
localhost can mean two addresses: 127.0.0.1 on IPv4 and ::1 on IPv6. If the server listens on only one of them and the client tries the other, the client gets a refusal.
Node.js changed how it orders addresses for a name. The Node.js dns documentation says the default order for dns.lookup() is verbatim: “addresses are not reordered.” The history on the same page notes that verbatim became the default in v17. In our test on Linux with Node 20, localhost resolved to ::1 first. Older Node versions sorted IPv4 first by default, so code that worked for years can start refusing after an upgrade.
Server defaults differ too. The Node.js net documentation says that if host is omitted, a server “will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise.” But a server started with an explicit 127.0.0.1 listens on IPv4 only. We started a Node 20 server on 127.0.0.1 and connected to ::1 on the same port: the result was ECONNREFUSED. Connecting to 127.0.0.1 worked.
Clients can work around this. Node’s net module has an autoSelectFamily option that, per its docs, “loosely implements section 5 of RFC 8305” and tries the IPv6 and IPv4 addresses in turn until one connects. Not every client turns that on, and older tools never had it.
Check a port before you touch the config, and see the process and path behind it.
Get it from Microsoft
What about Vite and other dev servers?
Vite’s server options say server.host defaults to 'localhost', and include a note that fits this exact problem: “Node.js’s dns.setDefaultResultOrder changes how DNS-resolved addresses are ordered, and browsers may use a different resolved address than the one Vite is listening to. Vite prints the resolved address when it differs.”
So read the address Vite prints, and open exactly that URL. To listen on every address, Vite’s docs say to set host to 0.0.0.0 or true, or use --host on the command line. That also exposes the server on your network, so only do it when you mean to. Our page on Vite port 5173 already in use covers the busy-port case.
Which fix should you use?
| What you found | Fix |
|---|---|
| Nothing listening | Start the server; read its startup output for errors |
| Listening on a different port | Use that port, or set the port in the server config |
| Listening on 127.0.0.1, browser tried ::1 | Open http://127.0.0.1:PORT, or set the server host to localhost or :: |
| Listening on ::1, a tool tried 127.0.0.1 | Point the tool at [::1], or bind the server to both |
| A proxy or API client refuses, browser works | Set the target to the exact address the server prints |
| Running inside WSL 2 | See our WSL 2 localhost port guide |
Avoid changing several things at once. Fix the address mismatch you found, and test the same URL again.
How does Port Detective help?
Port Detective is a native Windows app built in Rust. According to its Microsoft Store listings:
- Free edition. Live tracking of every active TCP and UDP connection, and instant lookup: type a port number and see the process name, PID and connection state. Pin your favorite dev ports to the top of the dashboard.
- Pro edition. Everything unlocked with one purchase: live tracking across IPv4 and IPv6, the executable path for the owning process, a Ctrl+K command palette, and copying any row as a ready-to-run netstat, taskkill or PowerShell command. One-click kill verifies a secure process token first, so a recycled PID does not take down the wrong app.
- Port Guard (Pro) watches pinned ports from the system tray every 250 milliseconds and notifies you when something unexpected grabs one.
For “refused to connect,” the first question is whether anything owns the port. An empty lookup tells you to start or fix the server; a hit tells you which process to check next. Our guide to finding the process using a port on Windows compares the command-line ways too.
Frequently asked questions
Is “refused to connect” caused by Windows Firewall?
Usually not for localhost. Microsoft describes error 10061 as a refusal that “usually results from trying to connect to a service that is inactive.” Firewall problems more often show up as timeouts.
Why does it work in one browser and not another?
Browsers and tools can pick a different address for localhost. Test 127.0.0.1 and [::1] directly to see which one the server accepts.
Should I bind my dev server to 0.0.0.0?
Only if you want other devices on your network to reach it. For local work, matching the address the server prints is enough.
Does Port Detective change my network settings?
Port Detective is built to show what is listening and to end a process you choose; in Pro, Port Guard rules can also shut down an intruder and relaunch the process that should own the port. Its Store listings do not describe changing bindings or firewall rules.
Try Port Detective
Port Detective is free in the Microsoft Store, and Port Detective Pro unlocks everything with a one-time purchase and a free trial. More detail is on the Port Detective product page.
Find out what is on the port before you edit a single config file.
Get it from Microsoft
Windows and Edge are trademarks of the Microsoft group of companies. Chrome is a trademark of Google LLC.
Last updated 21 October 2026. Published by Automata Labs, a software company in Canada.