a site for tech enthusiast

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:

1

sudo usermod-a-Groot[YOUR_GCLOUD_USER]

Run the update command:

1

sudo apt-getupdate

Install Node 6.x

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

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:

1

sudo npm install-ghttp-server

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:

1

sudo chown-Rsupport:root/usr/src

Now create the directory:

1

mkdir/usr/scr/app

Run http-server

Use the following command to run http-server:

1

sudo http-server/usr/src/app-p80

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: