Resolving port issue of node js application and windows server - node.js

Introduction :
My windows server is listening at port 3000.When i start my node application to use port 3000 for listening, it failed with error.
I understand that i have alternate method of deploying node app using iis but i failed.The only way left is making problem i.e "port".
Edit
When i unbind the port, i app start working.
If someone have better idea or idea about this problem, please do help. Thanks for your time.

Only one server at a time can use a given port. If your windows server is already using port 3000, then you can't start another server on that same port. You will have to either stop the first server or pick a different port number.
Or, use some sort of proxy as your only listener on port 3000 and have it divide the traffic among your two servers which would each run on different ports.

Related

Starting node http server at any free port

I am trying to start multiple highchart export servers via C# in a single windows machine. Highchart export server is run as node http server. All node servers are started from different non communicating applications running in a single machine. I am starting the process from c# code like this.
Process process = new Process { command line arguments to start node server with port };
process.Start();
How can I specify non conflicting ports in C# code so that node servers can be started in each application ?
Node.js can help you, use c# no problem.
You will need just to check port before you use it. If port is used you can't use that port this is basic rule for TCP/IP.
Take a look here :
NodeJS pinging ports
Also npm have some app for port checking.
https://www.npmjs.com/package/tcp-ping
Port is just a number you can use it on your will but would be better to follow standards. You can use 80 or 21 if port are free .

Hosting Nodejs application without port

I have a nodejs application running on port 3000. I wanted to host it on Linux environment. So I installed nodejs in it. It's working fine but I should specify the port each time.
example: mydomain.net:3000/url_i_want,
How can I avoid this. and also when running my app like that, all users are kind of connected to each others. If one of them disconnect all other users are. If one of them change page all others have there pages changing. Is it because they are all listening to the same port 3000 ? I searched and found that it can be related to PM2 and Nginx. Is it the solution ?
Whenever you load a URL without specifying the port number, the browser defaults to 80, because 80 is the default port number for HTTP.
So if you load http://stackoverflow.com/questions, the browser "converts" it to http://stackoverflow.com:80/questions.
If you don't want a port number to be specified to access your website, your app should be listening on port 80, instead of 3000.
However, it is not recommended for Node apps to directly listen on port 80 (although they very well can).
What you can do is use a front-facing proxy such as nginx, which accepts connections to the host's port 80, and then redirects the request to localhost:3000, where your app is listening.
It is best to ask one question at a time.
As for your second question, unless you are using some sort of "remote syncing" framework, that sort of behavior is unexpected. I would suggest posting a separate question for that issue with more details about it.

Socket server with Node.js and Cloud9 IDE

I am totally new to Cloud9 IDE, so my question amy be silly, but i can't find answer in docs. I want to make client - server application with Node.js + MongoDB as socket server, and client - desktop application which I debug and run on my machine (Cloud9 IDE doesn't support language on which I write it). Looking at Cloud9 IDE I've found it very nice for developing server-side part of my application and may be as hosting solution. But I can't find how to make socket connection from client. For this I need to know IP adress or domain address of my server (I suppose it looks like "https://socialcrm-c9-painkkkiller.c9.io") and port number.
In docs I've found about "use process.env.PORT as the port and process.env.IP as the host in your scripts!" but to connect to server I need they real values! Commands
console.log(process.env.PORT) and console.log(process.env.IP) gives me just "8080" and 0.0.0.0
Using "https://socialcrm-c9-painkkkiller.c9.io" as domain and 8080 as port gives me socket error. So is it possible at all? And if possible how to do it?
Cloud9 forwards port 80 of https://socialcrm-c9-painkkkiller.c9.io to port 8080 in your container. So there is no need to specify the port.
We do also support web sockets and they work in the same way. There's no need to specify another port.
The only thing you need to do is to make sure you are using the environment variables to connect to the right $IP and $PORT when starting your back-end process.
Old question - but I'm struggling with a similar problem. I don't have reputation to add a comment, but this should answer your question about getting the IP into your Cloud9 application.
You can reference process.env.IPto grab the IP... and fwiw, you can reference process.env.PORT to get the port.
Taken from:
https://community.c9.io/t/writing-a-node-js-app/1731

Node.js port compatibility

I'm starting an app in node.js, using socket.io and it's on the same server that runs apache, so port 80 is unavailable. By default, it's using port 8080. I read on socket.io's site that port 843 is generally not blocked.
I understand this is also the port used for flash files. Is there reason not to use port 843? or likewise, not to use port 8080?
Also, would the ideal solution be to use a different server and run on port 80?
Is there reason not to use port 843? or likewise, not to use port 8080?
Yes, I know some offices block all ports but the common ones (80, 21, 25, etc). If you're just testing node, playing around, or even during development, then it doesn't matter.
Also, would the ideal solution be to use a different server and run on port 80?
Yep.
Just run on port 8080, especially if you only use socket.io and not the complete node.js stack. Makes no difference if you ask me.

How do IP addresses work on a VPS? Routing a domain name to Node.JS

This is an absolute newb question. But I'm buying my first VPS for the reason that I want to install and start creating applications in Node.JS.
I can't visualise in my mind how the server works and where all of the applications such as Apache, Node.JS and PHP sit. I'm so used to a GUI.
I want www.mydomain.com to point to node.JS on my server, let's say Node is listening to port 8080. Now I know that HTTP defaults to port 80 of the IP address, so I can't use that. How do I set the domain up to resolve at www.mydomain.com:8080 - I read this wasn't possible...
My brain is melting.
Thanks :)
You just point the domain to your ip address as you normally do. The issue you will have it that HTTP default to port 80, so either you manually add the port at the end of the host to get to the page or you setup Apache to proxy specific urls to 8080, which gets some of your Node stuff appearing to work under 80.
If you aren't using Apache for anything you can also have your Node app bind to port 80. You will probably need to setup authbind or something to give your node app permission to bind to port < 1024.

Resources