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

October 8, 2017 89 views
Nginx Node.js Ubuntu 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?

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.

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.
Have another answer? Share your knowledge.