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

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.

Related

Port not running but app wont stop running in browser - Windows - React - Node

So when I go to localhost:3001 it shows project I worked on before. I restart my computer, its still there, kill all node/vscode processes in task manager, its still there. I tried the npx kill port 3001 - seems ok says "port killed" but, the app still there in localhost 3001. When I use netstat findstr 3001 shows nothing there. When I use CurrPort or cmd to check all ports listening - 3001 doesn't show up.
If I listen in port 3000, everything works normal, but when I npm start another app in React itll take me to port 3001 and it doesnt give any error. Except when it opens on Port 3001 it doesnt display the app I npm started in, it still shows that ghost app that I cant get out of port 3001.
In the network tab of the ghost app/port 3001 it shows port 3001 there. I cant post screenshots cus low reputation but idk if something with the initiators in network tab might give a hint to what the problem is.
I could always just set it so React uses 3002 onwards or just run one app at a time in port:3000 buts its bothering that this ghost app has taken over a port.
Hopefully its just something stupid Im overlooking, but if anybody ever had a similar experience let me know!
TL:DR my port 3001 is showing not running listening everywhere I check but everytime I go to it it shows this old project and if I try to run another app at the port terminal says its running, everything ok ,but it is still that old app still there
So it seemed to be something with the browser not port, worked normal in another browser. So went into the inspector tools of the browser went in storage and deleted all cookies, cache, local&session storage and that fixed it. Also killing the service-worker.js process in the port worked for someone else who had the same problem from the project.

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!

Unable to access node server running on specific port from other machine

I am running node server running react application.server is run by webpack. Server is running on 10.121.45.23:3005. I tried opening the application on other machine but page displays connection timed out. I have tried following things to resolve the issue, but nothing helped.
ping 10.121.45.23 from another machine. It is successful.
On server, netstat -ano. I am able to see 10.121.45.23:3005 listening. No loopback address was there as mentioned in many answers on Stack Overflow.
On another machine,telnet 10.121.45.23 3005. It fails and say cannot connect on port 3005. Telnet to some other port on which java is running, is successful. It fails only for node.js server.
So my problems are:
telnet is not working to that port.
Not able to open application on other machine's browser.
Am I missing any checks?
Sounds like you've tested quiet a bit. Have you tried another port, just in case there's a firewall or something?
Also, try explicitly telling webpack to listen on the all-hosts address 0.0.0.0
webpack-dev-server --port 9000 --host 0.0.0.0

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);.

Getting ECONNRESET response using node's http.get function

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!

Resources