Hosting Nodejs application without port - node.js

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.

Related

Which is best port to use for secure Chat server to allow general firewall bypass (port 443 is already occupied)

so I developed a public chat application which will run on a node server using secure socket.io.
That server, which only has a single IP address already has ports 80 / 443 occupied.
So I need to find the next best port to use for the chat server.
I wonder is there a recommended next best port that will allow most firwalls to communicate to? I know for example using ports like 21 (FTP) will normally be blocked.
And is it best to pick one above 1024 or below?
thanks
Sean.
In general 8443 will be the "alternative port for HTTPS", but you are still at risk of being filtered.
The proper solution should be to run proxy like nginx on port 443 and provide access to various applications based on the hostname, not the port. In example you can configure it to run your current app when user reaches https://example.com and chat app when user reaches https://chat.example.com.
Here is an example article showing how to do it https://www.manuelkruisz.com/blog/posts/nginx-multiple-domains-one-server
The idea is that each app runs on different internal port on the server, and proxy running on port 443 picks which app the request should be routed to based on the hostname.

Run node js application without port

I wants to run my application without assigning any port on my current IP address on port 80. How it will possible.
If your node.js application is a web server, you cannot remove the port. No port, no web server. Trying to make a web server without a port is like trying to make a locomotive with no railroad.
You can use the default port however. When users give browsers URLs without ports, they automatically apply the default port. For URLs like http://example.com/ or http://10.11.12.13/ the default port is 80. For https://example.com it's 443, and you need to use the https server class.
So, you can make your server listen on port 80.
In development you will run into a problem with this approach. On OSX, Linux, and other UNIX-derived OSs, only the privileged (root) user can run servers that use port numbers less than 1024. The typical development cycle of edit / run / test is a huge hassle, and a security hole, when you need privileges to run. That's why the node.js examples use port 3000.
In production, many people use nginx as a reverse proxy server to relay http requests from port 80 or https requests from port 443 to your node.js server at port 3000. You can read about how to do that; it's far beyond the scope of a Stack Overflow answer,

Resolving port issue of node js application and windows server

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.

significance of node.js port choice

I am a bit new to server side scipts. I am fairly capable with javascript so I decided to take a look at node.js as opposed to php or python ect. Correct me if I am wrong but it seems that when I code my webserver I may freely choose the port number I listen to. Is there any significance to this port number or may I choose any random number I wish? Will anyone be able to send a request to my server regardless of the number I choose?
Thanks in advance!
If you want to run node.js directly without any supporting web server or reverse proxy (no nginx, varnish, apache, etc), you need to listen on port 80 for HTTP and (optionally) 443 for HTTPS if you want normal URLs to work. Otherwise users will need to type the port number in the URL like http://example.com:3000 which is unheard of for public-facing sites.
However, you almost certain DO want to use a separate web server as I describe in detail here, in which case any port over 1024 is fine.
If you have root access you can choose any port that's not already bound to a process.
If you do not have root access you can choose any port above 1024 that is not already bound to a process.
Port 80 is usually the one you want to use if you're serving up HTTP, however, you can access an HTTP server on any port via the URL port syntax. For example, a server on port 3000. http://yourdomain.com:3000
If you're running on Linux and you do not want to run your Node process as root, you can redirect port 80 traffic to another port.

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