0
votes

For testing purposes, I've created a Google Cloud Compute Engine VM (Debian 9).

I installed nodejs and created a small script. When navigating to the external ip address through my browser, nothing happens.

const express = require('express')()

express.get('/', (req, res) => {
    console.log('browser access')
}

express.listen(8000, () => console.log('server is running'))

When navigating to http://[EXTERNAL_IP_ADDRESS]:8000, nothing happens.

  • I have SSH access through the external IP, it works

  • I can ping to the external IP address, this works too

  • When doing 'node app.js' through the terminal (SSH access), I see 'server is running'

  • I have set a firewall rule to accept all incoming trafic on tcp=8000 (IP range 0.0.0.0/0)

  • I have the firewall rules default-allow-http (tcp: 80) and default-allow-https (tcp: 443)

  • I have a static IP address

Is there something I'm missing?

Edit:

  • When I visit the server (with :8000) through my browser, the page keeps loading. But the message 'browser access' is not send to the console. After let's say 30 seconds, I get an ERR_CONNECTION_TIME_OUT in the browser.

  • Express version is 4.17.1. I also changed 'express' to 'app'.

  • When I open a terminal window and do 'curl EXTERNAL_IP_ADDRESS:8000', nothing happens. It seems like it keeps loading.

  • I changed listen(8000) to listen(8000, '0.0.0.0'). No differences are observed.

Problem solved:

I got it working. I installed ufw on the VM and opened up port 8000. That was the solution for me.

1
Can you elaborate on "nothing happens"? What messages do you see at the browser? Does Node.js express say something is reached? What are you expecting to happen? Do you see log messages written to the console? If you run netstat do you see something listening on port 8000? If you use CURL to port 8000 on the VM, do you get a connection?Kolban
Which version of express?John Hanley
Try this: express.listen(8000, '0.0.0.0'); Note: I would not call the variable express. You are masking the normal usage of app.John Hanley
@Kolban: I've edited my question, I've added the answers to your questions. I'm expecting to see 'browser access' in the console. I don't see any log messages except for 'server running'. When I use curl, I get an 'operation timed out'.yesterday
@John Hanley: express is version 4.17.1. I also changed listen(8000) to listen(8000, '0.0.0.0'). The problem stays the same. I also changed 'express' to 'app'.yesterday

1 Answers

1
votes

Solution:

Not only did I need to add a firewall rule to my VPC (0.0.0./0 tcp:8000, incoming), I also needed to open the port 8000 on my VM itself. I installed ufw and opened port 8000. It's working now.