Report this

What is the reason for this report?

How can I get Node.js to listen on port 80?

Posted on September 3, 2013

Hi! I followed the instructions here, https://www.digitalocean.com/community/articles/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps, and I got a Node app up and running on port 3000. When I direct requests to that port, I see my app, but not when I send a request without specifying a port.

I tried running $ PORT=80 node app, and Node threw an error and quit. It worked when I used PORT=8080 though.

On IRC, @kamal_ suggested I install and configure NGINX to to serve the static files “and pass everything else to Node.js”, and now I have NGINX up and running. When I go to my droplet’s IP now, I see “Welcome to nginx!” instead of having the connection refused, but I still have to append :3000 to the URL to see my Node app.

This is the NGINX config file I got from @kamal_: https://p.kk7.me/mepayofuqo.nginx

What are the next steps to making the app load on requests to the default port?

Thanks in advance!



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 use the proxy

   server_name  example.com;
    access_log /var/log/nginx/your.log;
    location / {
            proxy_pass http://127.0.0.1:3000/;
    }

Launching the app with sudo works fine. There’s probably security implications. I’m not a backend guy. But it will work for now.

Edit: No, it’s not… I give up.

Thanks for this ressources! Check this course it’s straight to point and it gives you all the keys to a good start for a complete masteration of node.js by taking all the power of it. https://www.udemy.com/nodejs-tutorial-from-scratch-by-examples/

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.