NodeJS on App Engine Standard

Eric Jiang
MonPlan
Published in
4 min readJun 12, 2018

That’s right, it’s finally happened NodeJS has arrived 🛬 on the Google App Engine (GAE) Standard Environment across the Google Cloud Platform. To read more about this release, head over to

“Node.js has offered Monash University a very flexible framework to build and develop rapid prototypes and minimal viable products that provide our stakeholders and users with scalable solutions for their needs. The launch of Node.js on App Engine standard has added the bonus of being a fully managed platform, ensuring our teams can focus their efforts on developing products.”
- me

What is different about this? Well, NodeJS was running on the GAE Flex environment, this means that:

  • we had slower instance spin-up times and had a lower scalability.
  • it is directly built on top of Google Compute Engine (GCE) or a Docker Image, meaning that we have to pay for the VM hours.
  • More serverless apps! 🎉

Whereas being on the Standard Environment means that we are directly built on Google’s scalable infrastructure. All of this was possible because of gVisor — ‘a new kind of sandbox that helps provide secure isolation for containers, while being more lightweight than a virtual machine (VM). gVisor integrates with Docker and Kubernetes, making it simple and easy to run sandboxed containers in production environments.’ (Google Cloud Platform Blog, May 2018).

This alsomeans that it is cheaper for business to use NodeJS, as it is on the Standard Environment compare to the Flex Environment.

All serverless applications hosted in Google App Engine is managed by Google.

Migration to Google App Engine Standard

Migrating to your new GAE Standard Environment is actually more straightforward then you think. All you need to do is ensure that your NodeJS application can be run on Node 8 (LTS).

# runtime: nodejs
# env: flex
# GAE runs on Node 8 by default
runtime: nodejs8
env_variables:
NODE_ENV: "qat"

And this should just work. But if you are running something like Express, ensure the port is using process.env.port for example

var express = require("express");
var app = express();
app.get('/', function(req, res){
res.send('hello world');
});
app.listen(process.env.PORT || 8080);

Well, let’s get into it shall we?

Building a simple application on NodeJS

Very straightforward, we are going to do some nom init after cloning your repo, we are also going to install express using yarn add express or npm install express --save

Your package.json should look like:

We will also be adding our Express app (when we use the port we will be using the port provided by an environment variableprocess.env.port and will fallback to 8080), we will also be adding the start script node index.js to the package.json file.

Now, onto deploying to Google App Engine. Firstly, you’ll need to install the Google Cloud SDK, which can you install from here.

Now we’ll create a new Google Cloud Project, go to https://console.cloud.google.com (if you don’t have an account, go ahead and create one, you’ll get $300 free credit with 1 year expiry to use on GCP).

Name a random project (test is attached to my Monash Staff Account, for demo purposes)

We then use our Terminal and run to set the current project as our dif

gcloud config set project gap-node-std-test

We also want to set up our app.yaml configuration file.

Then all, we need to do is deploy. Use gcloud app deploy If this is your first time, follow the prompts.

NodeJS deployments also in Early Access used the Container Builder API, enable this API (meaning that you’ll probs need the billing enabled), you can follow the recording below.

You can do alot more awesome things such as using Google Datastore (NoSQL) as your database solution, Bigquery and Stackdriver. But I’ll touch on that in a later article.

You can find an example build here: https://github.com/lorderikir/node-gae-standard-example

Hi there! I’m Eric, and I’m current the Lead Developer on MonPlan. I am a Full Stack Developer and DevOps Engineer. If you enjoyed this article, why not give it some ❤️ and some 👏

--

--

Eric Jiang
MonPlan
Editor for

I build software, travel and take photos | 👨‍💻 GitHub: github.com/ericjiang97 |👀 Views are my own