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
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
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
If you're using WSL (linux on windows), restart its service LxssManager Servie (run services.msc) and try again.
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.
I was also facing this problem on mac m1 from last 2 days, so finally i ended fixing the issue by :-
In my case I have an error with require in setupProxy.js
In my case, deleting the node_modules and then reinstalling using npm install
worked.
In my case, I resolved the issue using "npm start" command again in terminal of vs code and it works.
In my case I had made changes to the setupProxy.js that caused the problem. Try reverting back to something that is working, such as:
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/api',
createProxyMiddleware({
target: 'http://localhost:5000',
changeOrigin: true,
})
);
};
the problem of "localhost refused to connect." is occur because of command prompt that you closed so you must keep open your command prompt after hit "npm start" command till you work in "App.JS" file.
i'm sure this will work 100%.