Node.Js App Can't Run on Port 80 Even Though There's No Other Process Blocking the Port

Node.js app can't run on port 80 even though there's no other process blocking the port

The error code EACCES means you don't have proper permissions to run applications on that port. On Linux systems, any port below 1024 requires root access.

Node.js app can't run on port 80 even though there's no other process blocking the port

The error code EACCES means you don't have proper permissions to run applications on that port. On Linux systems, any port below 1024 requires root access.

How do I run Node.js on port 80?

What you need to do is have 2 ip's for the server you are running. Apache has 1 ip bound to port 80 and then node.js has the other ip bound to port 80.

Using node and its listen directive has 2 values eg. .listen(80, NODEJS_IP or DNS NAME);

Some other advice.

I would not use apache with nodejs as it's not evented. So this really isn't recommended. I would actually look into using NGINX as its a much better pairing with Node.

Best practices when running Node.js with port 80 (Ubuntu / Linode)

Port 80

What I do on my cloud instances is I redirect port 80 to port 3000 with this command:

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000

Then I launch my Node.js on port 3000. Requests to port 80 will get mapped to port 3000.

You should also edit your /etc/rc.local file and add that line minus the sudo. That will add the redirect when the machine boots up. You don't need sudo in /etc/rc.local because the commands there are run as root when the system boots.

Logs

Use the forever module to launch your Node.js with. It will make sure that it restarts if it ever crashes and it will redirect console logs to a file.

Launch on Boot

Add your Node.js start script to the file you edited for port redirection, /etc/rc.local. That will run your Node.js launch script when the system starts.

Digital Ocean & other VPS

This not only applies to Linode, but Digital Ocean, AWS EC2 and other VPS providers as well. However, on RedHat based systems /etc/rc.local is /ect/rc.d/local.

run node.js webbapp on 80 port on windows

On windows machine you 80 port probably busy with IIS Server. Try to stop iis first and after run node.js webapp with port 80.

node.js is listening on port, but cant connect from the outside on Ubuntu Server

Sounds like a firewall issue. There are two things to look for, first is IPTABLES, which will show you the firewall rules on the local server. https://help.ubuntu.com/community/IptablesHowTo

With AWS instances, they also belong to Security Groups, and you will have to edit this security group to allow traffic on port 9000 as well. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-network-security.html

Need help getting simple node.js express to run

Start with simple stuff...

Use express-generator to create simple app by the following command

1-> npm install -g express-generator with root or Admin access

2-> Run express demoapp.

3-> Navigate to demoapp

4-> Do npm install

5-> Run from command with npm start: it run by default on http://localhost:3000

Hit that URL from Browser



Related Topics



Leave a reply



Submit