Deploying a Node 12 Function to Cloud Run

Deploying a Node 12 Function to Cloud Run

In this post, we’ll learn how to deploy a Node 12 application using the Functions Framework and Cloud Run.

Originally published by Grant Timmerman at

Let’s say this.

  • You learn that the Node Foundation releases cutting-edge
  • Node 12
  • .It includes cool new features like more performant async/await, faster HTTP parsing, and private fields. It’s still in development but you want to use it for your services.But Google Cloud Functions doesn’t support Node 12 yet.

So whatchagunnado?

  • Blog about it?


  • Or use Cloud Run

Let’s learn how to do that!

Deploying a Node 12 Function to Cloud Run

Node is a JavaScript runtime built on Chrome’s V8 engine.

Cloud Run ( is a managed, serverless computing platform that abstracts away infrastructure management, so you can focus on building great applications.

Together, you can build scalable services atop Google Cloud in minutes.

First, Install Node 12

TJ has an incredibly simple Node module called n for managing Node versions (i.e. switching between 10 and 12). Install the global CLI called n:

sudo npm i n -g

Then switch your Node version to Node 12:

sudo n 12

Verify your Node version

node -v # v12.7.0

Create a Node 12 Function

Create a new package.json:

  "name": "ffnode12",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "functions-framework"
  "dependencies": {
    "@google-cloud/functions-framework": "^1.2.1"

Hard to make it simpler than that!

Create a class in greeter.js that uses Node 12 private fields:

class Greeter {
  #name = 'Functions Framework';
  get name() {
    return this.#name;
  set name(name) {
    this.#name = name;
  sayHello() {
    return `Hello, ${this.#name}`;

module.exports = Greeter;

#private field

Create an index.js file:

const Greeter = require('./greeter');

exports.function = (req, res) => { const g = new Greeter();

// Can't access private fields // greet.#name = 'NewName';

res.send(g.sayHello()); };

Private fields are inaccessible!

Test the Functions Framework locally

You’ll want to test your service locally to ensure you code works.

So we got things working locally. But how do we deploy this to Google Cloud? Read on!

Next, we’ll use Cloud Build + Cloud Run

Create a Dockerfile

OK. I’ll be honest. If you asked me 6 months ago what Docker was, I’d mumble something about boxes, container ships, and a blue whale. But…

Docker is really nothing to be afraid of. It is an open platform for developing and running applications. To run an application, you’ll need to create some instructions for Docker to set up your environment.

Create a file called Dockerfile (no file extension) as such:

# Use the official Node.js 12 image.

FROM node:12

Create and change to the app directory.

WORKDIR /usr/src/app

Copy application dependency manifests to the container image.

A wildcard is used to ensure both package.json AND package-lock.json are copied.

Copying this separately prevents re-running npm install on every code change.

COPY package*.json ./

Install production dependencies.

RUN npm install --only=production

Copy local code to the container image.

COPY . .

Run the web service on container startup.

CMD [ "npm", "start" ]

A basic Dockerfile for Node applications

We’ll tell Docker, use Node 12, copy our package.json we defined above, install, copy our files, then start our server!

Deploy to Cloud Run

To deploy to Google’s Cloud Run, follow these 3 steps:

1 - Setup gcloud

# Install gcloud beta services
gcloud components install beta# Set env var "GCP_PROJECT" to our project name
GCP_PROJECT=$(gcloud config list --format 'value(core.project)' 2>/dev/null)# Set our Cloud Run region (so we aren't prompted)
gcloud config set run/region us-central1

2 - Upload your code and build the container

# Build and upload your image in Google Container Registry
gcloud builds submit --tag$GCP_PROJECT/helloworld

Notice each command in the Dockerfile gets executed (30s)

3 - Deploy to Cloud Run

# Deploy your container to Cloud Run
gcloud beta run deploy --image$GCP_PROJECT/helloworld --platform managed

Deploy our container to Cloud Run (17s)

You’ll get a URL that looks like this:

Congrats! You deployed the Functions Framework to Cloud Run.

node-js cloud web-development serverless docker

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire Node.JS Developers | Skenix Infotech

We are providing robust Node.JS Development Services with expert Node.js Developers. Get affordable Node.JS Web Development services from Skenix Infotech.

How to Hire Node.js Developers And How Much Does It Cost?

A Guide to Hire Node.js Developers who can help you create fast and efficient web applications. Also, know how much does it cost to hire Node.js Developers.

Top Node.js Development Companies and Expert NodeJS Developers

A thoroughly researched list of top NodeJS development companies with ratings & reviews to help hire the best Node.JS developers who provide development services and solutions across the world. List of Leading Node.js development Service Providers...

Node.js Live | Node.js Docker Tutorial | Dockerizing Node.js App|Node.js Training|Edureka

🔥 Node.js Certification Training: This Edureka video on 'Node.js Docker Tutorial' will help you in learn...

Hire Web Developer

Looking for an attractive & user-friendly web developer?, a leading web, and mobile app development company, offers web developers for hire through flexible engagement models. You can **[Hire Web...