Report this

What is the reason for this report?

Is it possible to run a Node.js application that is accessible to the internet without a reverse proxy?

Posted on August 16, 2017

Is it possible to run a Node.js application that is accessible to the internet without a reverse proxy?

If so how does one set it up? IP and port wise.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

You can actually do this with iptables pretty easily:

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

You’ll want to add that line (minus sudo) to your /etc/rc.local file as well to start the redirection on boot. This also assumes you’re running your app on port 3000 (configured in your code), but you can redirect it to wherever by changing the final value in that command.

Alternatively, if you’re using Express, the app.listen call accepts a hostname or IP address:

app.listen(80, <the IP address you want to listen on>, function() {<your callback here>});

I’ve heard a lot of people say not to run apps directly on port 80, and although I can’t think of a reason off the top of my head, instinctively it seems like a bad idea. Any particular reason you don’t want to use a reverse proxy?

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.