The Cloud Functions Node.js 6 runtime is based on Node.js version 6.16.0. For instructions on how to 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
The Node.js 6 runtime is generally available and is the default runtime selected when you deploy your function.
If you are using the
gcloud command-line tool, the Node.js 6 runtime
is selected by default. For example:
gcloud functions deploy NAME --trigger-http
For more arguments that you can specify when you are deploying, see Deploy using the gcloud tool.
If you are using the GCP Console, you can select the runtime when you create and deploy a function.
In the GCP Console, go to the Cloud Functions Overview page.
Make sure that the project for which you enabled Cloud Functions is selected.
Click Create Function.
Under Runtime, select Node.js 6.
The execution environment includes the runtime, the operating system, packages, and a library that invokes your function.
The Node.js 6 runtime uses an execution environment based on Debian 8 with Node.js version 6.16.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.
You can specify dependencies for your functions by listing them in a
package.json file. For more information, see
Specifying dependencies in Node.js.
Using middleware to handle HTTP requests
Node.js HTTP Cloud Functions provide
that are compatible with
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.