express.js server starts on a port that is being used - javascript

Have this setup:
expressjs server started from one node process, listening to port 8081.
js client trying to make a request to it from another node process, using node's http module.
client failing with 400 error.
same URL (http://localhost:8081/) is opening in browser just fine.
Spent a few hours trying to troubleshoot it, then tried to change the port and it worked.
Turns out there is another process listening on port 8081:
$ lsof -i tcp:8081
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
EUSAManag 1187 oleksandr.suhak 4u IPv4 0xce3bb9546cff3ab1 0t0 TCP localhost:sunproxyadmin (LISTEN)
(Have no idea what EUSAManag is)
I guess my question is: how could it be that the express server starts fine without complaining to a "port being used by another process" when the port is clearly in use. And why does it work then when accessing it from the browser, but does not work when making request from js client? Any tips on figuring out what is actually happening here?

If guess that EUSAManager.exe come from one of software https://iit.com.ua/downloads which is in the business of information security. Most likely their software interfere too much with you operation system.

Related

WebSockets working on localhost, but do not work on remote Ubuntu host

I have two applications - browser based client and NodeJS based server that are both communicating using WebSockets (I'm using ColyseusJS library). Problem is, that everything works fine while I'm testing them on localhost but when I deploy the application to my Ubuntu VPS server it stops working.
The message I receive in the browser while trying to connect is:
WebSocket connection to 'ws://X.X.X.X:8001/?colyseusid=' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
So it reaches the server (because when server is disabled the message is "Error in connection establishment: net::ERR_CONNECTION_REFUSED") but it looks like it fails on Upgrade connection operation.
What is strange is that I managed to make it work yesterday (don't know how exactly), but had so much mess on my VPS that I decided to revert machine to it's starting state. After that it stopped working (code is unchanged). Maybe there are some additional dependencies that I need to install in order to make it work on my Ubuntu Server?
I would really appreciate your help.
Have you tried to port forward the port to the ip address of the said VPS in your router config? And also check out the firewalls.

How to start Node.js in specific URL?

When I'm updating (and testing) a specific page in my application, I need to stop the server, start again with node server.js, switch to the browser window, hit F5 and switch back to the terminal to see the output. This takes a lot of time.. :)
Is there a way I can start Node with something like this:
node server.js -url /my_page
so I can directly see the output as if someone hit the page from their browser?
I found this question but I guess it's included in the server code so it needs to be updated each time too. It is a solution, but I wonder if there is a faster way to do this.
Thanks,
Edit:
With curl, I'm getting this error:
$ node server.js & curl 'http://localhost:5000/my_page'
[2] 12824
curl: (7) Failed to connect to localhost port 5000: Connection refused
[1] Terminated node server.js
$ Listening on port 5000
Notice the last line, is it executing curl before the server is started?
node server.js & curl 'http://localhost/my_page'
This starts the server in the background, then immediately uses curl to make an HTTP request.
The server will still be running after this. You can bring it to the foreground (e.g. in order to kill it) with fg. Alternatively just run the two commands (without &) in separate terminals (or screens).
If the server doesn't start fast enough, just add a delay:
node server.js & sleep 1 ; curl 'http://localhost/my_page'

Make sails.js listen for remote connections

I want my development environment to be accessible from remote connections as well as local. I have changed my local.js config file to listen on port 80 and host 0.0.0.0.
netstat -ab | more output:
Port forwarding:
And my firewall is disabled. however, the app is not accessible via browser and remote IP, nor can it be seen by http://canyouseeme.org.
All the command prompt windows are run with lifted privileges.
I currently don't have the option to run it as --prod if that would change anything.
EDIT: Tried fixing problems with production environment, and running as --prod, still same problem. Also tried setting up the simplest possible node.js server, and it also had this same problem, which leads me to believe, that it's problems with my router, and not sails.js. Any ideas, what could be preventing this?
Let's make your app listen on another port (for example 1337) then forward traffic from port 80 to port 1337.
Another way, you can use Nginx in front as a reverse proxy. By this way, Nginx will handle traffic on any port (80 as your requirement) and forward to your Sails app.
Hope this helped!

How to access remote node.js app in browser, not on localhost

I'm trying to set up a simple "Hello world" node.js app.
I've created the following index.js file:
var app = require("express")();
var http = require("http").Server(app);
app.get("/", function(req, res){
res.send("<h1>Hello worlddddd</h1>");
});
http.listen(8080, function(){
console.log("listening on *:8080");
});
When I open up my local console, and perform node index.js, I get the message "listening on *:8080", as expected. I point my browser to localhost:8080, and I see the HTML page saying "Hello worlddd", as desired.
Now, I'm trying to do the same on my Virtual Private Server, so I can access the same app from different computers, but all I get is connection timeouts. I've followed these steps:
Install node.js on my VPS
Install express via npm install --save express#4.10.2
Upload my index.js file to the var/www/html folder on my server with IP 192.123.123.12 (an example, this isn't my real IP).
Access the server via PuTTY, and run node index.js, where I get "listening on *:8080", so I know node.js is working.
Now I point my browser to http://192.123.123.12:8080 and after about 20 seconds, I get the browser error: "The connection has timed out".
I've tried listening to port :80 instead, but I get the error that this port is already in use.
Does anybody know what I'm doing wrong? Am I using the wrong port? Am I pointing to the wrong URL? Do I need to modify my server preferences? (running Apache on CentOS). I've only found dozens of tutorials that teach you how to run a node.js app on your local computer(pointing the browser at localhost:8080), but I need it to run on my remote server so multiple computers can access the same app.
The issue is that your current filters (iptables) block traffic unless you explicitly allow it.
You just need to open port TCP 8080 inbound, and you should be able to reach your node.js server!

Sails.js server not starting anymore

I am using Cloud 9 IDE to develop a simple CRUD application using Sails.js (node.js MVC framework). Up until today I had no trouble starting the Sails.js server.
Today, I've been trying to start the sails js server, but I keep getting this error:
warn: error raised: Error: listen EACCES
error: Server doesn't seem to be starting.
error: Perhaps something else is already running on port 8080?
I have checked my /config/local.js file and everything is just fine, as it should be. The port is set to process.env.PORT || 1337 so it shouldn't have any problems firing the server up.
I'm looking forward to your insight.
Thank you!
Open terminal and run this command:
$ lsof -i :8080
Output will show PID of process occupying port 8080: "httpd 1234 ....'
Then kill the process with this command
$ kill -9 1234
Sails will now run
Hmm-- looks like port 8080 isn't available. What happens if you try to switch the port? You may have another server running on that port. Or in some cases, hosts require the hostname to be set. I'd try switching the port first though.
The only real answer to this is: wait. C9 seems to kill servers in a weird way that causes Sails to jack up and blocks you from establishing another server. lsof -i doesn't show anything serving... but it still won't start. Seems to be an issue with Cloud 9 and Sails.js. If I serve a generic Node.js "Hello World" app on the same port, the issue doesn't occur. However, time, it seems, cures all. After awhile, Sails seems to snap out of it and starts serving again when lifted.
Incredibly weird.

Categories

Resources