The Node.js 8 Runtime

For instructions on how to prepare your local machine for Node.js development, see Setting Up a Node.js Development Environment.

To get started with Node.js on Cloud Functions, see the Quickstart.

Selecting the runtime

You can select the Node.js 8 runtime for your function during deployment.

gcloud

If you are using the Google Cloud CLI, you can specify the runtime by using the --runtime parameter. For example:

gcloud functions deploy NAME --runtime nodejs8 --trigger-http

For more arguments that you can specify when you are deploying, see Deploy using the gcloud tool.

Console

If you are using the Google Cloud console, you can select the runtime when you create and deploy a function.

  1. In the Google Cloud console, go to the Cloud Functions Overview page.

    Go to the Cloud Functions Overview page

    Make sure that the project for which you enabled Cloud Functions is selected.

  2. Click Create Function.

  3. Under Runtime, select Node.js 8.

Execution environment

The execution environment includes the runtime, the operating system, packages, and a library that invokes your function.

The Node.js 8 runtime uses an execution environment based on Ubuntu 18.04 with Node.js version 8.15.0. See Cloud Functions execution environment for more information.

Source code structure

In order for Cloud Functions to find your function's definition, each runtime has certain structuring requirements for your source code. See Writing Cloud Functions for more information.

Specifying dependencies

You can specify dependencies for your functions by listing them in a package.json file. For more information, see Specifying dependencies in Node.js.

Async/await

Node.js 8.x is the first LTS version of Node.js to support the async and await keywords.

Using middleware to handle HTTP requests

Node.js HTTP Cloud Functions provide request and response objects that are compatible with ExpressJS to make consuming HTTP requests simple. Cloud Functions automatically reads the request body, so you will always receive the body of a request independent of the content type. This means that HTTP requests should be considered to have been fully read by the time your code is executed. The nesting of ExpressJS apps should be used with this caveat—specifically, middleware that expects the body of a request to be unread might not behave as expected.