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

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

Related

Node.js / curl(7) failed to connect to localhost port 3000. How to fix it?

response from testing
code hello.js
i am trying to create a web service with node.js. Unfortunately after implementing the application hello.js i am only able to test successfully "node hello.js", but furthermore when i type in "curl http://localhost:3000" i am getting "curl: (7) Failed to connect to localhost port 3000: connection estavlishment rejected"
This also happens with other ports oder when i type 127.0.0.1 directly. I also disabled my firewall with ufw and allow 3000 with ufw.
I am working with VirtualBox for a uni project. I am running everything in the VM. The goal is to cluster with docker and i need the web server for loadbalancing in the end.
Thanks!
The issue here that you use same terminal for multiple processes. As soon as you start the server, it holds the terminal. It means when you press Ctrl + C (^c in terminal output), you stop the server.
In your case you should use two terminals. In the first one you start the server (and do nothing with this particular terminal), in second one you make the request. Or you can change second step and make request from browser (it will be GET request by default), Postman, Insomnia etc.

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

Unhandled rejection SequelizeConnectionError: connect ENOENT

I am stuck at a point. I am trying to start /connect using command "npm start" but unable to start npm on server.
I am getting this error:
Unhandled rejection SequelizeConnectionError: connect ENOENT
at Handshake._callback (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:63:20)
at Handshake.Sequence.end (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/mysql/lib/protocol/sequences/Sequence.js:96:24)
at Protocol.handleNetworkError (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/mysql/lib/protocol/Protocol.js:358:14)
at Connection._handleNetworkError (/home/ec2-user/webapps/vactivity/node/vactivity/node_modules/mysql/lib/Connection.js:382:18)
at Socket.emit (events.js:95:17)
at net.js:441:14
at process._tickCallback (node.js:442:13)
Apart from this my website work on nodejs & have nginx server configured on server.
Every thing started when I tried to set apache for adding a wordpress blog website. Since nginx already working on port 80. I was trying to set apache on another port so that everything work and ended up with above error. Now my website is not starting at all.
Edit:
My website is running using nodejs. I needed a wordpress blog website to run along and so i checked if there is a scope for apache on my server.
I found that apache along with nginx service was already running and mysql as well.
nginx is essential to run "adminer", a database management tool
Since nginx and apache was running on same ports, i tried to set apache on another port, other than default port.
After that I restarted apache, stopped mysql, stopped nginx and also stopped node
I used pkill node command for stopping node service.
Then restarted everything but got the above error.
I tried many things, and finally reset everything.
Ever since then I am stuck on this error.
Can anyone help?
I finally figured the problem and solved it.
Connect ENOENT means that system is unable to connect to mysql because its path is not correct.
As mentioned in an approved answer from Connect MySQL with Sequelize
Update your models/index.js file with the mentioned code.
To find you mysql socket path go to file here /etc/mysql/my.cnf ( this path may depend on your server). For my case it was /etc/my.cnf. Here you will find the socket path. Now paste this path to the code above and do npm start.
Problem is resolved. :)

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.

connecting jconsole to linux box connection failed

I am new to linux and just deployed a java program to run on a linux server. I tried to connect from my windows machine to the linux box with jconsole and got an error.
Connection Failed: non-JRMP server at remote endpoint
I searched online and found the following suggestion was to run the following:
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=
[YOUR PORT] -Dcom.sun.management.jmxremote.ssl=
false -Dcom.sun.management.jmxremote.authenticate=false -jar [YOUR JAR NAME]
I entered the following into a batch file and executed it. I then tried to connect using jconsole using the follow command
service:jmx:rmi:///jndi/rmi://ipaddress:port/jmxrmi
as suggested but still cannot (Connection failed: retry)/
I got the same issue but the reason was different, I was hitting http port instead of JMX port.
The error message appeared same as in your case but later I figured out it was port issue.
Since JMX process runs on different port so be careful while opening JConsole on remote server.
Resolved situation by setting hostname to ipaddress when calling process on linux
I faced this problem at localhost.
Wrong port was used.
So, I changed my JMX port to be different from application port in my run configuration and yet, the port changes did not take effect until the application container was restarted.
Fixing above resolved my issue.
Another possible reason for error message Connection failed: non-JRMPserver at remote endpoint: the RootCA-certificate of the server hasn't been added into the client's cacerts file.

Resources