Connection refused on localhost - node.js

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

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

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

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.

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.

I was also facing this problem on mac m1 from last 2 days, so finally i ended fixing the issue by :-
Run 'npm start' from default shell(/bin/bash) on vs code.
You can also try to update the node version.
You may need to change the port for application only if some other application is running on default port(3000)

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,
})
);
};

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

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%.

Related

JFrog Artifactory OSS: UI service unavailable, "Trying to connect an http1.x server"

I'm trying to set up a new JFrog Artifactoy OSS server on a Windows 10 machine.
While it actually seems to be up and running the UI is not working. When trying to open http://localhost:8082/ui/ I just get a "Service unavailable" error.
In the /var/log/frontend-service.log I see the following error:
[main ] - Couldn't register on Router, retry number: 120, Error : [Trying to connect an http1.x server]
I couldn't find any errors in the other logs.
I already made some desperate attempts in my system.yaml like setting the IP manually, tested setting a proxy, etc. But no luck. Any ideas what might be going on here?
I also had the same problem, I solved it by exposing port 8082 as well:
docker run --name artifactory -d -p 8081:8081 -p 8082:8082 docker.bintray.io/jfrog/artifactory-oss:latest
I had this issue with version 7.7.3 and I just reverted to an older version I had 7.5.7 and it worked fine for me.

ForestAdmin: Unlock your data. CORS configuration issue

I try to install ForestAdmin but get an error after set up my account and generate my lumber db.
What I did :
lumber generate -c 'mongodb+srv://ugo:<my-password>#tlf-qraep.mongodb.net/test?retryWrites=true&w=majority' test
cd test
npm install
npm install lumber-forestadmin --save
lumber install lumber-forestadmin --email <my-mail> --projectName test
npm start
I got this message so I clicked on it
Your admin panel is available here: https://app.forestadmin.com/49189
I re-entered my password but I got this error message :
"Unlock your data
Oops, cannot reach your application. Are you sure it is running? If your application is running, you might have a CORS configuration issue."
I checked and my server running on port localhost 3000.
Someone already got this error message?
Thx for the help guys.
I finally succeed to remove the error. I generated a new lumber on an other port (3003 rather than 3000) and it worked for me !
Maybe another app is using the 3000 port ?

Failed to connect before deadline

When I run query.js (similar to query.js in fabcar but modified for my application), I keep getting an error which says,
Failed to connect before the deadline
I have changed the localhost to docker IP address in enrollAdmin.js and registerUser.js
TLS is enabled for peer, orderer and cli.
Any help would be appreciated. Thanks
I had the exact same problem. These steps fixed it for me:
Open VirtualBox Manager and select the “default” VM
Click “Settings”, “Network”, “Advanced”, “Port Forwarding”.
Create a new rule by clicking the “+” sign on the right and entering the following: Name -> “grpc”, Host Port -> 7051, Guest Port -> 7051
You can leave the Host IP and Guest IP unspecified.
Thx to: https://developer.ibm.com/opentech/2017/11/29/running-hyperledger-fabric-windows-revised/
I had the same problem:
I think grpc and fabric-client package has issues or different versions than we need (verify the package.json for npm) . Therefore I decided to manually install the latest versions of the npm fabric-ca-client, fabric-client and grpc packages and it worked!!!!
I hope this solution works for you!!
I had the same issue as well
What works for me is that I reinstall the global window-build-tools and global grpc, and it works afterwards. Hope it helps!
What worked for me was changing the localhost to Docker's IP(seen when the docker terminal starts) in the network connections file(either connections.json or networkConnections.yaml) being used in the query.js(or any other js).

Getting the node.js monitor-dashboard project to work externally

I'm trying to get the monitor-dashboard project to work but i get a page can't be found error when I try to use a browser externally.
http://lorenwest.github.io/monitor-dashboard/
Internally seems OK, I'm getting a HTTP/1.1 200 OK from http://localhost:4200 with the usual curl command.
I went in to node/node_modules/monitor-dashboard/config/, and changed default.js and external.js and changed all occurrences of allowExternalConnections to true.
I've also got node-monitor loaded in to my node project.
I'm running node server.js first and then npm start monitor-dashboard in another window.
port 4200 is open via iptables -L
Any ideas?
The setting you're looking for is:
export NODE_ENV=external

Node.js, WebSocket Location Issue?

I created a server using Node listening on port 8000, localhost. Verified it's running properly, but I cannot access the WebSocket on the client (Chrome 5). Tried several implementations from various Git repos, node + websocket, socketIO, articles, etc. Nothing.
No port conflicts (sudo lsof -i tcp);
Tried server.listen(8000, "*");
Pointed to ws = new WebSocket("ws://:8000/test");
Debian Lenny, Apache22
Node v0.1.98-31-g1c6671a
I'm thinking there may be a conflict with url rewrite. Or possible permissions. Any ideas?
I had a similar issue on Ubuntu 10.04 LTS 32-bit and Chrome 5.0.375.125 and found out it is a bug in Chrome.
Here's how you can test and work around the problem. I used WebSocket with PHP and later Node.JS:
PHP: Download a tutorial file from http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/ and extract it in a folder called 'socket' in your webroot. This folder now contains a readme.txt and the folders 'server' and 'client'. Now start the script in the console according to the readme (for me the command was: sudo php -q /var/www/socket/server/startDaemon.php ). It should print 'Start listening on Socket.' . Leave the console window open. Now go to localhost/socket/client/client.php in Chrome. It should say 'Socket Status 0' and if you look in the console you see no new messages (no connection was made).
Now here comes the trick: open a second Chrome tab. Point this tab to the same url: localhost/socket/client/client.php (It also says 'Socket Status 0'). And then close it again. Your original tab should now say 'Socket Status: 1 (open)' and in the console you see a handshake was made. WebSocket now works.
I repeated the same trick as above but this time using Node.JS with the Socket.IO script. The chat example included in Socket.IO-node ( github.com/LearnBoost/Socket.IO-node ) had the same issue, hanging at the 'Connecting...' stage. Opening a second tab to the chat box and then closing it again solved the problem and the chat box proceeded to load properly. The Node.JS server confirmed the connection in the console. From then on WebSocket worked fine.

Resources