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.
Related
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,
how can I hide the port when I ran my node application
example
http://localhost:3000/application/login
What I need is to hide port 3000 so that it stays that way
http://localhost/application/login
You need to run the server on port 80, but to do this, you need root privileges, and it used to be a bad idea.
Phrasing it a bit differently.
When you open a http:// url, browsers will by default use port 80. Only if you specify a port, browsers will try a different port instead.
So if you don't want the port to appear in the url, you must use port 80.
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.
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.
I noticed that almost all examples of Express.js applications use port 3000 as the default listening port for HTTP servers. Is this just because it's a rarely used port, or is there any other reason for this port number?
If I want to run multiple apps side-by-side on my local machine, is it good practice to use ports like 3000, 3001, 3002, etc.?
(I understand that ideally, you'd let the system assign ports. This is just a question as a matter of simplicity, and why 3000 seems to be a conventional assignment.)
3000 is a somewhat arbitrary port number chosen because it allows you to experiment with express without root access (elevated privilege). Ports 80 and 443 are the default HTTP and HTTPS ports but they require elevated privilege in most environments.
Using port 3000 in examples also helps indirectly emphasize that you ideally want to put your express app behind nginx or Apache httpd or something like that which would listen on port 80 and/or 443.
There is no reason (that I'm aware of, anyway) why 3000 is better than 8000 or 4000 or 8080 or any of a number of other port numbers that are accessible without elevated privileges.