Time to “Hello, World”: running Node.js on VMs, Containers, Apps, and Functions

Overview of compute service-abstraction ladder

This article is a part of the series: Part 1 (overview), Part 2 (VMs), Part 3 (containers), Part 4 (apps) and Part 5 (functions & summary).

Do you want to build applications in the cloud but have no idea where to start? This series will walk you through building a “Hello World” Node.js application on virtual machines (VMs), containers (Kubernetes), platform-as-a-service (PaaS), and function-as-a-service (FaaS) offerings on Google Cloud Platform (GCP).

Just a few months ago, before joining Google, I also had no idea where to start with Node.js and GCP. To prepare for my interview, I watched most of the GCP Next 2017 talks, including Brian Dorsey’s Deciding between Compute Engine, Container Engine, App Engine, which inspired me to go and build something across the Google Cloud computing stack. To make this exercise more fun (and also to make sure I could manage it within the time constraints of a single weekend), I timed things and took notes. I found it very helpful both in terms of getting a feel for GCP as well as boning up on the fundamentals of web application development (hello 2018!). Today, I want to share some of my interview prep notes with you. If you are building your first web application or are generally interested in getting up and running with Node.js, you are in the right place! By the end of this post, you’ll be equipped to write a “Hello World” web application across the GCP compute stack: Google Compute Engine, Google Kubernetes Engine, Google App Engine, and Google Cloud Functions.

So, where do I run my code?

(Short answer: it depends… ) Here’s a condensed version of Dorsey’s GCP Next 2017 talk:

Deciding between compute options

Generally speaking, it boils down to the following three criteria:

  1. Level of abstraction (what you want to think about).
  2. Technical requirements and constraints.
  3. Where your team and organization are going.

Depending on the problem you are trying to solve, technical constraints can pull you down the stack. For example, if you need a very specific kernel, you might be down at the base layer (Compute Engine). The following article offers a set of constraint-based questions to help you navigate the fundamentals: Choosing the right compute option in GCP: a decision tree.

What is Node.js?

Node.js is an asynchronous JavaScript runtime designed for building scalable web application back-ends. Let’s unpack this sentence:

  • Asynchronous means first-class support for asynchronous operations (compared to many other server-side languages where you might have to think about async operations and threading — a totally different mindset). It’s an ideal fit for most cloud applications, where a lot of operations are asynchronous.
  • Node.js also is the easiest way for a lot of people who are coming from the frontend world (where JavaScript is the de-facto language) to start writing backend code.
  • And there is also npm, the world’s largest collection of free, reusable code. That means you can import a lot of useful functionality without having to write it yourself.

Pretty cool, huh? I am convinced!

On your marks… Ready, set, go!

We’ll start with Compute Engine and VMs first, and then move up the levels of compute service-abstraction ladder, to Kubernetes Engine and containers, App Engine and apps, and finally Cloud Functions. As a reminder, this is not a tutorial but recall of my journey (if you decide to follow along, please be sure to read the whole section before lifting commands).

Continue on to:

  • Part 2: building with VMs (Compute Engine)
  • Part 3: building with Docker containers (Kubernetes Engine)
  • Part 4: building on top of PaaS (App Engine)
  • Part 5: building with FaaS (Cloud Functions) & summary