Start Node.js server on Digital Ocean

2k views Asked by At

I have created a Node.js Droplet on Digital Ocean.

I have connected to the server with FileZilla and uploaded all the Node.js files (index.js, package.json, etc.).

I am trying to start the server with node index.js. It says

App is running at http://localhost:3000 in development mode
  Press CTRL-C to stop

However, I am not able to see the website neither on the public IP address provided by Digital Ocean nor on localhost:3000.

How do I start the Node.js server correctly?

Edit

I am setting up the server with this (content of index.js):

const express = require('express');

const app = express();

app.set('port', process.env.PORT || 3000);

app.listen(app.get('port'), () => {
  console.log('App is running at http://localhost:%d in %s mode', app.get('port'), app.get('env'));
  console.log('  Press CTRL-C to stop\n');
});
1

There are 1 answers

1
Dennis On

First you want to ensure everything is running fine by opening another terminal on the same machine and executing a curl.

curl http://localhost:3000

After you have confirmed that is working, you will have to open the appropriate ports on the machine.

Let's see what ports are currently open by running the below command.

sudo ufw status verbose

If port 3000 isn't listed, lets add it with the following command.

sudo ufw allow 3000/tcp

Verify port 3000 has been added by running ufw status again.

sudo ufw status verbose