Running Node and Express on Ubuntu VM

So you just spun up your first Ubuntu Virtual Machine?
Let’s fix that: “Intro to Ubuntu on Azure”

Let’s put it to work!

The Basic Steps to using node on an Azure VM:
1. Open the Port
2. Install Git and Install Updates
3. Install Node and NVM
4. Code and Install Express
5. Run it and check it out!
6. Use forever to keep it alive

1. Open the Port
We’re not talking battleships or submarines we’re talking Infrastructure as a Service.
Visit the landing page for your Ubuntu Virtual Machine:

And select the resource group in the top left corner:

Resource groups are the way we break down how our VM interacts with the internet, other vms, storage, and public/private networks.

To open the port we need to change our network security group which is represented by the shield. (Underlined in the above screenshot)
Then we’ll select settings -> Inbound security rules

This will allow us to open up our VM to the Public Internet so we can visit it like any other website.

Under ‘Inbound security rules’ SSH is already included:

We’re going to add a new Inbound security rule named ExpressServerPort where we’ll set the Destination port range to 3000 which we’ll see later when starting our server. Here’s the configuration pane for our ExpressServerPort:

2. Install Git and Check Updates
Git is fun!

SSH into our Virtual Machine like we did in the VM intro then enter:
$ sudo apt-get install git

Yay! We have Git

Let’s run our update command just to double check we’re up to date:

$ sudo apt-get update

Great let’s move on with Node!

3. Install NVM and Node

First NVM:

NVM is a version manager for Node you can install using curl:
Enter this command to install it:
$curl -o- | bash

Then source your profile to add it to your commands:
$ source ~/.profile

Then check out the version to make sure it installed:
$ nvm --version

It should look like this:

NVM is installed!
Let’s install a version of Node!
$ nvm install 5.0

Then check our version of Node:
$ node -v


Check out NVMs readme on the github for more commands:

With node comes ‘npm’ which allows us to install a whole bunch of node awesomeness. One of the more popular packages is express a minimalist web framework, we’ll install this to start coding away.

4. Code and Install Express

We’ll be following along “Express’s” introduction if you get lost/have more questions about express.

First let’s create our a directory, cd into it and initialize our app using nom.

$ mkdir myapp
$ cd myapp
$ npm init

After entering npm init we’ll be walked through a configuration step for our app. The only one that matters for now is (index.js) which will be the entry point for our app everything else can be the default for now.

If you were actually going to submit/share this code you’d want to accurately fill out this info.

After the initialization step we’ll add express and list it as a dependency:
$ npm install express --save

Here’s what those steps look like:

Weeee now have express and an app ready for your code!

Lets open nano and put the helloworld sample into index.js

$ sudo nano index.js


Now lets run our app!
$ node index.js

Now that its running lets visit it by entering the IP address and port number into our browser.
In my case the URL is:


6. Use forever to keep it alive
Unfortunately, if we close our Terminal/SSH Connection our project will stop running.
To solve this, we use another NPM package called forever.
Here’s the link to the repository with clear instructions.

In short we install it globally:
$ sudo npm install forever -g

Then start it:
$ forever start app.js

And stop it:
$ forever stop app.js

That’s it for now!

Now clone one of your node projects and run them in the cloud!
Happy Hacking!

When the Male Roommates are home alone...
When the Male Roommates are home alone…

Intro to Ubuntu Virtual Machines on Azure

When I search:
Node JS Server Azure, Ubuntu, JavaScript, Mongo, Postgres, Flask, VM
I turn up with all sorts of unhelpful results.
So I dedicated a couple days to creating a couple guides for common Cloud Stacks on Azure VMs to make it as simple as possible to start deploying your code to the cloud.

This is the introduction and at the bottom of this blog post you’ll see other workflows fill in.

So, Here’s a guide to deploying an Ubuntu VM on Azure:
1. Gather Materials
2. Create VM
3. Check VM using SSH

1. Gather Materials
Here’s what you’ll need:
An Azure Account
An SSH Client perhaps putty… or even Bash On Windows?

2. Create VM

Head into the Azure Portal:

And Select Virtual Machines -> Then ‘Add’

You’ll then see a page like this:

Select Ubuntu Server 14.04.

There are lots of configurable deployments available if you feel like exploring.

Then select Create, but make sure the deployment model is Resource Manager as its more future ready then the classic model:

We’ll then get to the basic configuration tab, fill out the info and pick a User name and Password that you’ll remember because you’ll need it later!


If you’re not familiar with Resource Groups check out THIS ARTICLE

I’ve named my resource group: ResourceGroupOne

Hit Okay to go to the next configuration pane

Select the Size of your VM. To see all the options select ‘View All’

We’re going to go with the cheapest option A1 Standard:

Hit Okay to take us to our final configuration Pane, “Settings”.


There are a number of different settings presented here.

First up is Storage:
This will configure what we want to name the storage account for our vm. I’ve changed mine to ‘resourcegrouponestorage’, but I could have selected any of my previous storage account in the same region, in this case westus.

Second is Network:
We can configure a Virtual Network to allow our virtual machines to connect to other resource on our network by default. We can also change this later. So in this case I’m creating the default virtual network.

Again, I could have selected a previously created Virtual Network Called ‘Databases’ which is in the same region.

Third is Extensions:
We won’t add any extensions

Fourth is Monitoring:
Which we’ll disable for simplicity sake, but is a very powerful tool one you start needing to make scaling decisions.

Fifth and finally is Availability:
We won’t use an availability set, until we need to scale out our app.

Here’s what the lower portion of our settings pane looks like:

And we’ll select OK to finish with our settings. This will take us to the summary page so we can do a one more check on our machine, don’t get to anxious about making mistakes because we can always tear this one down and spin up another if we messed something up!

Hit Okay one last time!

You’ll then be taken to your dashboard where you’ll see a nice loading tile:

It’ll take ~5 minutes to spin up and then we’ll be ready to take on the world!

Once ready it’ll look like this:

Click the tile to hit the landing page for our VM:

See that public IP address?
We’ll use that to SSH into our machine.

In my case: !

3. Check VM using SSH

Let’s SSH into our box.

Pull out your preferred SSH client. Here’s bash on Windows and Putty Side by Side:

Notice ‘Timothy’ Triple underlined?
That’s the User Name we set during basic configuration and is paired with the password that we also set in Azure.

When you connect you might have to accept the ras2key fingerprint. It’ll look like this when using putty. Or it’ll be in the terminal using bash. Type ‘yes’ or Select Yes to continue.

Then type in your password and marvel and your creation:

Let’s test our vm by installing updates! Yay Updates!

$ sudo apt-get update

Now that you have a VM ready let’s put it to work!

Host a Node Server
Host a Python Flask Server

Pradeep Cruising on National Donut Day
Pradeep Cruising on National Donut Day