Question

What else is required to access node app outside of the DigitalOcean droplet?

Posted October 8, 2017 6.1k views
NginxNode.jsUbuntu 16.04

Originally posted on SO

We have set up a node server which runs on PORT 5000.

In a newly created droplet, we have installed and started nginx. To access the node app, we have changed the default port from 80 to 5000 in /etc/nginx/sites-enabled/default

server {
        listen 5000 default_server;
        listen [::]:5000 default_server;

ufw is enabled

sudo ufw enable

Also the port is enabled

sudo ufw allow 5000/tcp

Also, tried this way too:

sudo ufw allow 5000

As confirmed with sudo ufw status

sudo ufw status

Also the app is configured to listen on the public interface

const server = app.listen(process.env.PORT || 5000, '0.0.0.0', () => {
    console.log('Express server listening on port %d in %s mode', server.address().port, app.settings.env);
});

However, not even the default PORT was responding. HENCE, reverted to 80 as the default PORT.

What else is required to access node app outside of the droplet?

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.

×
1 answer

First of all, you can’t have Nginx and Node.js listen on the same port, which is in your case :5000. You can have only one app listening on the same port at the time.

Second, if you want to use with Nginx, you have to setup Proxy Pass as described in the How To Set Up a Node.js Application for Production on Ubuntu 16.04 tutorial.

Then, you should be able to use Node.js + Nginx if you want to do so.

by Brennen Bearnes
Node.js is an open source JavaScript runtime environment for easily building server-side and networking applications. Node.js applications can be run at the command line but this guide focuses on running them as a service using PM2, so that they will automatically restart on reboot or failure, and can safely be used in a production environment.
Submit an Answer