"Localhost refused to connect" means your computer received the browser's request on that port and nothing was listening there to accept it. Start the server, then make sure the URL uses the port the server printed and the address it actually listens on.
Chrome shows this as "This site can't be reached", "localhost refused to connect." and the code ERR_CONNECTION_REFUSED. Chrome's own help page describes that code only loosely, as the page not letting Chrome connect. On localhost the meaning is narrower and easy to check: the connection reached your machine and was turned away because no program owns that port. Replace 3000 with your port in every command below.
Start here: is anything listening on the port?
Everything else in this article depends on one fact, so test it first. On Windows, in PowerShell:
Get-NetTCPConnection -LocalPort 3000 -State Listen
Microsoft documents -LocalPort and -State as filters, and Listen is one of the accepted states. If a server is listening, you get a row with its local address and port. If nothing is listening, PowerShell reports that no matching objects were found. On macOS and Linux:
lsof -i :3000
No output means nothing is listening. In that case the browser is behaving correctly, and the job is to find out why your server is not up. If something is listening but the browser still refuses, skip to the sections on addresses and protocols below.
Cause 1: the server is not running
This is the most common cause by far. Look at the terminal where you started the server. Typical reasons it is gone:
- It crashed on startup. A syntax error, a missing environment variable or a database that is not reachable can end the process right after it prints the "listening" line, or before. Scroll up and read the first error, not the last.
- You closed the terminal or the IDE window. Closing the window stops the process that was running inside it in most setups.
- You are in the wrong folder. Running the start command in a directory without the project's config either fails or starts something else.
- A watcher restarted and failed. Tools that reload on file save can leave nothing running after a save that introduces an error. Fix the error and the tool usually brings the server back.
Start the server again and wait for its ready message before you open the browser. Some frameworks take several seconds to compile, and a refresh during that time is refused.
Cause 2: wrong port in the URL
The browser connects to exactly the port in the address bar. If you leave it out, http://localhost means port 80 and https://localhost means port 443, and a dev server is almost never there. Read the startup message for the real port. The same project can also move: Vite's documentation says that if its default port (5173) is already in use, Vite automatically tries the next available port, unless server.strictPort is set to true, in which case it exits instead. So after a restart, a server that was on 5173 yesterday may be on 5174 today while an old tab still points at 5173. Always copy the address from the current startup output.
If the server refuses to start because another program holds the port, see how to fix "port already in use". For what the number after the colon does, see what a port number is.
Cause 3: localhost resolves to IPv6 but the server listens on IPv4
The name localhost can resolve to two addresses: 127.0.0.1 (IPv4) and ::1 (IPv6). A server bound to only one of them refuses connections that arrive on the other. A good test is to try both addresses in the browser:
http://127.0.0.1:3000http://[::1]:3000
If one loads and http://localhost:3000 fails, you have found the cause. Node.js makes this more likely: its documentation says that dns.lookup() returns addresses unsorted (verbatim), and that this became the default in Node v17.0.0. Before that, IPv4 addresses were placed first. Node can be told to prefer IPv4 with dns.setDefaultResultOrder('ipv4first'), which is documented for the Node side of the problem. For a server you control, the cleaner fix is usually to set its host explicitly. Vite, for example, documents server.host with a default of localhost, and says that setting it to 0.0.0.0 or true makes it listen on all addresses. Note that this exposes the server to your local network and possibly beyond, so use it only when you need other devices to connect. The wider background is in what localhost is.
Cause 4: http versus https
If your server speaks plain HTTP and you open https://localhost:3000, the browser tries a TLS handshake that the server cannot answer. Depending on the server you may see a refusal, a reset or an SSL protocol error. The reverse mistake, plain http:// to an HTTPS-only server, fails in a similar way. Type the full address with the scheme your server prints. Browsers can also remember a redirect to HTTPS for localhost and keep applying it. If a plain-HTTP server worked yesterday and now refuses, open the address in a private window to rule out a remembered redirect.
Cause 5: the server is in Docker, WSL or a virtual machine
A container has its own network stack. A server inside it that listens on 127.0.0.1 is reachable only from inside the container, and a server with no published port is not reachable from the host at all. Both produce a refusal in the browser. The usual fix is to make the app listen on 0.0.0.0 inside the container and to publish the port when you start it, for example -p 3000:3000. Docker port mapping walks through the syntax.
The reverse direction also trips people up: from inside a container, localhost means the container, not your computer. A database on your laptop is not at localhost:5432 from there. The same applies to a virtual machine: localhost in the guest is the guest.
Cause 6: the hosts file or a proxy changed what localhost means
If 127.0.0.1 works but localhost fails for every program, someone may have edited the hosts file so that localhost points at a different address. Open the file and check; how to edit the hosts file shows where it lives on each system. A system or browser proxy can also catch local traffic. If the proxy program is stopped, every request through it is refused, so check the proxy settings if localhost and ordinary websites both fail.
A quick diagnosis order
| Check | If yes | If no |
|---|---|---|
Does Get-NetTCPConnection or lsof show a listener on the port? | Go to the next row | Start the server and read its startup errors |
| Does the port match the one in your URL? | Go to the next row | Correct the URL |
Does http://127.0.0.1:PORT load? | IPv4/IPv6 mismatch: use the working address or bind both | Check http versus https, then the hosts file and proxy |
| Is the server in a container or VM? | Publish the port and bind to 0.0.0.0 inside | Look at the server's own logs |
If it still fails
Test outside the browser so the browser's cache and extensions are out of the picture. curl -v http://127.0.0.1:3000/ prints each address it tries and the result, which separates "nothing is listening" from "something answered with an error". If curl connects and the browser does not, try a private window or another browser. If curl is also refused, the problem is the server and not the browser, so return to the first check and read the server's logs for the first error after startup.
Frequently asked questions
- Why does localhost refuse to connect when my server says it is running?
- The most common reasons are a different port than the one in the URL, a server that listens only on IPv4 (127.0.0.1) while the browser tries IPv6 (::1) first, or a server that crashed after printing its startup line. Check the port in the startup message and test http://127.0.0.1:PORT directly.
- Is 'localhost refused to connect' a problem with my internet connection?
- No. Traffic to localhost never leaves your computer, so Wi-Fi and your ISP are not involved. The error means your own machine answered and said no program is listening on that port.
- Why does 127.0.0.1 work but localhost does not?
- localhost can resolve to both 127.0.0.1 and ::1. If the server listens on only one of them and the client tries the other, that attempt is refused. Use the address that works in the URL, or make the server listen on both.
- Do I need to change the Windows firewall to fix it?
- Usually not. A firewall that silently drops packets causes a timeout, and loopback traffic on your own machine is rarely filtered. Start by confirming that a server is listening on the port; touch the firewall only if something is listening and the connection still fails.