37

I use the node.js and socket.io.

My application runs on the port 3000. The application starts from from the url: mydomain.com:3000/

I want to run the application from mydomain.com - I want to remove the port from the url.

Where and how can I set this setting?

Jenan
  • 3,408
  • 13
  • 62
  • 105
  • Also the search would brought this up: http://stackoverflow.com/questions/14303690/nodejs-domain-without-port-number – TheHippo May 02 '13 at 19:27

4 Answers4

24

Find your server.listen call and change the port from 3000 to 80. Don't forget that you have to run the program with the CAP_NET_BIND_SERVICE capability (see capabilities(7) for details) in order to bind to ports less than 1024 on Linux systems. root privilege will contain this, and other, privileges.

sarnold
  • 102,305
  • 22
  • 181
  • 238
  • I tried to set the port to 80 The application was dropped. It's forbidden. – Jenan Mar 02 '12 at 00:56
  • "The application was dropped"? What does that mean? Are you running it as `root`? Can you? – sarnold Mar 02 '12 at 00:58
  • Conosle writes line: info - socket.io started, warn - error raised: Error: EACCES, Permission denied – Jenan Mar 02 '12 at 01:01
  • 2
    Running the command as `root` would solve the issue but that would make your site extremely insecure. The proper solution is to use a Reverse Proxy and then bind a directory, say "mydomain.com/app" to the port 3000. – adelriosantiago Sep 17 '15 at 22:53
  • How to run in windows Machine – Trojan Dec 02 '16 at 14:10
  • @Trojan, I don't think Windows has any restrictions on who can open low ports. If you're still having trouble, I recommend starting a new question with a ten-line program that demonstrates your problem. That will draw more attention from more experts. Thanks. – sarnold Dec 08 '16 at 18:50
  • 1
    Running your node.js server application on port 80 is not considered safe. – ConfusedDeer Jul 20 '18 at 21:08
13

If you want to run it "without a port" like you describe, you're actually going to be running it on port 80. You can't do this without root permissions.

So instead of

node server.js

You need

sudo node server.js

This is assuming you have sudo permissions on the machine you're trying to run it on. Otherwise you're going to run into EACCESS problems. That's what sarnold is trying to tell you.

Aashay Desai
  • 3,093
  • 3
  • 18
  • 16
11

This is how I did it because I'm using apache as well I can't use port 80 because it reserves it. So, I setup a proxy pass. I set my /src folder to be ignored.

<VirtualHost *:80>
    DocumentRoot "/Library/WebServer/Documents/www.mysite.com"
    ServerName local.www.mysite.com
    ServerAlias local.www.mysite.com
    ProxyPass /src !
    ProxyPass / http://local.www.mysite.com:3000/
    ProxyPassReverse / http://local.www.mysite.com:3000/
</VirtualHost>
Anna
  • 544
  • 9
  • 21
  • Hi, I wanted to do exactly the same thing but failed. In errorlog it says `[Fri Nov 29 18:45:45 2013] [error] (111)Connection refused: proxy: HTTP: attempt to connect to my.IP.addr.0:3000 (www.mydomainname.com) failed`. Which proxy module you are using (http, ftp, ajp etc.)? – Boyang Nov 29 '13 at 18:49
  • Hey Charles- I am using the default apache setup for proxies. The only thing I changed to make the proxy work was this bit in my vhosts. My apache config has all the proxy modules loading. And apache is listening to port 80 in my config. Are you not loading any of the modules? – Anna Dec 04 '13 at 13:55
3

First, you probably want to be running the application from your localhost, "127.0.0.1". You can remove the port just by omitting it in the node.js setup. By default, web browsers look for servers on port 80. If you want your server running on port 3000 for some reason, it will have to be included in the URL.

  • There is no solution? It has to go set the application to run on the server on this port without url. – Jenan Mar 02 '12 at 00:54
  • Sorry, I misunderstood. I do not believe there is a way to run on port 3000 without including this in the URL. I could be wrong though. – feralcreature Mar 02 '12 at 00:57