Getting ECONNRESET response using node's http.get function - node.js

I finally figured out what was causing this problem and didn't find any direct answers online, so I thought I'd post an answer (below). Anyway, here's the problem:
I have a simple node app running on port 3000. I was trying out some database connection pooling, and I wanted to load test it to make sure it was working the way I expected. I installed siege and tried:
$ siege -c 10 -r 10 -b http://localhost:3000
I got a Connection reset by peer error. So I tried reducing the number of connections:
$ siege -c 1 -r 1 -b http://localhost:3000
Same problem. I thought maybe it was a problem with siege, so I tried nperf and got a ECONNRESET error. Same with artillery.
The weird thing is that I could connect using curl, telnet, and the web browser and got a valid response.
I tried logging errors in the express app, but it never seemed to receive a request. I tried monitoring network traffic using nettop, but it never showed a connection using siege or nperf (though it did using curl).
I wrote a client app to connect using the same method that nperf uses (node's http.get function), and got the same ECONNRESET response.
I wrote a simple express app running on port 3001 and it worked fine! I tried commenting out most of the lines in my port 3000 app so it was basically the same as my 3001 app, but it still didn't work. I was beginning to suspect that webpack was doing something strange, and then finally started to realize...see answer below.

Maybe there's another program on port 3000!
So, I ran:
$ sudo lsof -i -P | grep -i "listen"
and I found an old VM I'd forgotten to halt, that had port 3000 exposed (another project). I shut it down and everything worked great!
I thought node warned if a port was being used, but for some reason it didn't notice this one.
Anyway, if you're getting a similar error, do a port scan!

Related

Vue application running on Digitalocean times out in browser

First time I try to use a node.js droplet on Digitalocean: I have a vue.js application running on port 8080, but it times out when I try to load the masterpiece in the browser (I don't have a domain so I use the [server IP]:8080 to access it).
I made sure 8080 is open in the firewall (ufw):
Netstat -pln gave the result seen in the screenshot below, a node program is running but nothing is named vue in case that would be required:
Tried export HOST=0.0.0.0 on advice from a friend, but didn't seem to do anything.
Tested curl 127.0.0.1:8080 from the digitalocean console and it works correctly.
The browser error message is err _ connection timed out.
Any tips on how to get this to show in the browser? As I'm not experienced in working with servers please give me step by step instructions. Thanks!

I can only access NodeJS server locally

My server's hosted at DigitalOcean (it's a droplet) and basically, I cannot access my NodeJS app via Internet, only server-side. It's running on port 9000, I've allowed traffic to the port via ufw and iptables, no luck. When I run curl || wget while SSH-ed to the server, I get a normal response as if everything's in order. But when I try to access the server from an another machine, I just get timed out because the server returns nothing. I've heard DigitalOcean sometimes disable connections to all ports except ssh,www and ssl, but I think I've successfully 'opened' them. Any suggestions?
This is what I get when I run netstat -tulp | grep LISTEN
Turns out my dashboard was all messed up when it comes to ports, which I forgot to check, of course, so opening them directly on the server gave no results whatsoever.

I get a EADDRINUSE error when I try to start a node.js server on OpenShift

So, I successfully commited a node.js app to OpenShift - without getting any error - but it does not work (error 503 when trying to access it through my browser, connection timeout when running tests against it from my local machine). The output when commiting says that node and mysql start successfully, and that the build succeeded.
I accessed the server through ssh, and checked the node log. It says an EADDRINUSE occured: Error: listen EADDRINUSE :::8080.
In my configuration, I use:
"server":{
"host":"OPENSHIFT_NODEJS_IP",
"port":"OPENSHIFT_NODEJS_PORT"
}
I also checked available environement variables in the shell with export and both are there, and 8080 is the right port.
When running ps in the shell, it does show only the programs ps and bash running. EADDRINUSE should mean that the port is already in use by another program, but I don't see anything running... I can't run netstat (permission denied).
I tried various combinations of stop/start/restart, but I always get the same error.
I am pretty lost at this point. Any pointers would be appreciated!
I found the problem. Locally, I used to start the server with app.listen(port);, which is enough to run it and access it on localhost. But that does not work on OpenShift. The host needs to be specified too: app.listen(port, host);.

localhost:3000 connection refused after app.js is set (Windows 7)

I've followed this manual of installing MEAN stack https://thecodebarbarian.wordpress.com/2013/07/22/introduction-to-the-mean-stack-part-one-setting-up-your-tools/
and I got stuck on the point where I should be able reach for localhost:3000 successfully, but instead I get ERR_CONNECTION_REFUSED. I checked the ports using
netstat -an
and it seems my port 3000 is not even open. My Apache is working on port 80 and after reaching for localhost:80 everything works fine (I even checked if closing the Apache helps). The only thing I changed in the manual is that I installed both express and express-generator thanks to this install express with npm.
Can anybody tell me what should I do additionally so my port 3000 responds?
EDIT: I also checked the host files in system32, the only localhost address I have is 127.0.0.1 (three times, though!)
EDIT2: Solved, same issue as here: Express Node.js doesn't work
Remember to change the app.js file in the folder you are currently working in!

Error: listen EADDRINUSE when trying to run an Express.js application?

When I try to run my application an Express.js server, the first time with a new port works fine, but then when I try to run it again on that port, I get the "Error: listen EADDRINUSE" error.
I already tried killing all the possible node/gulp processes, also, checked netstat and I do not see port 8080 being used by anything.
What could be the culprit?
This usually happens if the node process is still running your app when you go to run it again. Express will try to bind to the same port but it's already being use by the last node instance you created.
Kill all node processes and try again.
I know that this post is very old. But right now I saw something.
When I was in the same situation as you are in, I opened the console in my browser and I can see some errors. When I solved those errors, everything works fine.

Resources