In previous article we had learn together how to spin up a vm instance in Google Cloud Compute Engine, so today we will look deeply into how to setup this vm and run a NodeJS application inside so later on we can access it from the internet.

Update Operating System Packages

This update is just to make sure that we get the newest package version from Debian official repository, these new packages may contain bugs fix or security patches.

Add your current user to root group:

Run the update command:

Install Node 6.x

When I’m writing this article NodeJS 6 is the LTS version so we will install it in our machine.

Check installed NodeJS version:

check nodejs version

check nodejs version

Install http-server

http-server is a simple, zero-configuration command-line http server and can be installed through npm (node package manager). To install http-server run the following command in terminal:

Create Web Root Directory

Web root directory is a directory where we can put our website content into, all contents be accessed from internet unless we specify restriction rule for it. In this tutorial I’ll set my web root directory to /usr/src/app.

By default the /usr/src folder is owned by root, this can bother us in the future when adding or removing something from web root directory so we need to change the folder ownership to current user:

Now create the directory:

Run http-server

Use the following command to run http-server:

You can now access it from browser at: http://your_public_ip_address, but it still showing an empty page because we haven’t create any single file yet, let’s create index.html and then refresh the browser:

hello google cloud

hello google cloud