'Connection refused on localhost

I am trying to work on my nodejs and reactjs app at school but everytime I run the server, I get an error with localhost:PORT/net::ERR_CONNECTION_REFUSED

Is the wifi refusing the connection on localhost?

PS: The react side renders correctly



Solution 1:[1]

Try changing the url from localhost to 127.0.0.1 . If it works, then it means your environment is not resolving localhost to 127.0.0.1

Or Try with changing the PORT Number

Solution 2:[2]

If you're using WSL (linux on windows), restart its service LxssManager Servie (run services.msc) and try again.

Solution 3:[3]

For those of you that the approved solution didn't work for (changing localhost to 127.0.0.1) I was able to fix this just by restarting my computer. Not sure what caused the issue but the day before today my app was working fine and then today I got hit with this error. Restarting fixed the issue.

Solution 4:[4]

I was also facing this problem on mac m1 from last 2 days, so finally i ended fixing the issue by :-

  1. Run 'npm start' from default shell(/bin/bash) on vs code.
  2. You can also try to update the node version.
  3. You may need to change the port for application only if some other application is running on default port(3000)

Solution 5:[5]

In my case, deleting the node_modules and then reinstalling using npm install worked.

Solution 6:[6]

In my case I have an error with require in setupProxy.js

Solution 7:[7]

In my case, I resolved the issue using "npm start" command again in terminal of vs code and it works.

Solution 8:[8]

Rebooting the system (linux) worked for me. Consider rebooting first.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Maulik Sakhida
Solution 2 Olavo André Parno
Solution 3 AJRohrer
Solution 4 WasitShafi
Solution 5 Mohit Kushwaha
Solution 6
Solution 7 Subhash Karthik
Solution 8 sai_varshittha