1

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!

gloo
  • 2,490
  • 3
  • 22
  • 38

2 Answers2

1

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.

Community
  • 1
  • 1
Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
0

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.

Community
  • 1
  • 1
Daniel
  • 38,041
  • 11
  • 92
  • 73