3

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');
});
Jamgreen
  • 10,329
  • 29
  • 113
  • 224
  • 1
    Who knows... it's your application, how you specify the bind host is dependent on your code! Only you can answer this. Somewhere you want to bind to `::` or `0.0.0.0` (which is a pseudo address indicating you want to listen on all interfaces, in IPv6 or IPv4, respectively). You'd also want to make sure that you don't have a firewall blocking `:3000`... but who knows how to help you there as you didn't even tell us what operating system you're running. – Brad Sep 04 '17 at 07:33
  • Alright, now that you've posted your code... your application is listening on all interfaces already, so this is going to come down to firewall config. – Brad Sep 04 '17 at 07:36
  • I'm sorry. I have just installed a Droplet with Node.js on Digital Ocean. The operating system in Digital Ocean is Ubuntu. My own operating system is OSX. It says I haven't created any firewalls on https://cloud.digitalocean.com/networking/firewalls. – Jamgreen Sep 04 '17 at 07:38
  • 2
    Probably a firewall on your Ubuntu system, not the Digital Ocean cloud firewall. – Brad Sep 04 '17 at 07:39

1 Answers1

4

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
Dennis
  • 3,962
  • 7
  • 26
  • 44
  • Can you please take a look at the following question:https://stackoverflow.com/q/66858780/9409877 – HKS Mar 30 '21 at 09:37