Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in AWS by (19.1k points)

I create and launch an app like this:

express -s -t ejs

npm install express

npm install ejs

node app.js

and it works (on port 3000). But when I go and change the port to 80, then running node app.js outputs this:

node.js:198

throw e; // process.nextTick error, or 'error' event on the first tick

          ^

TypeError: Cannot call method 'getsockname' of null

at HTTPServer.address (net.js:746:23)

at Object.<anonymous> (/var/www/thorous/app.js:35:67)

at Module._compile (module.js:432:26)

at Object..js (module.js:450:10)

at Module.load (module.js:351:31)

at Function._load (module.js:310:12)

at Array.<anonymous> (module.js:470:10)

at EventEmitter._tickCallback (node.js:190:26)

This works too on my laptop, but not on my Amazon EC2 instance, where port 80 is open. Can figure out what's wrong. Any tips?

1 Answer

0 votes
by (44.4k points)

The lower port numbers which you have used required root privileges. Also, you should never run a Node.js application on port 80 with root privileges, that is a risk. So, you can run an nginx as a reverse proxy for your application which is running on a port. (e.g. port 3030)

You can forward traffic from port 80 to 3000.

sudo iptables -t nat -A prerouting -p tcp --dport 80 -j redirect --to-ports 3000

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
3 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...