The Cloud Functions Node.js 10 runtime is based on Node.js version 10.15.3. 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 10 runtime for your function during deployment.
If you are using the
gcloud command-line tool, you can specify the runtime
by using the
--runtime parameter. For example:
gcloud functions deploy NAME --runtime nodejs10 --trigger-http
For more arguments that you can specify when you are deploying, see Deploy using the gcloud tool.
If you are using the Cloud Console, you can select the runtime when you create and deploy a function.
In the Cloud 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 10.
The execution environment includes the runtime, the operating system, packages, and a library that invokes your function.
The Node.js 10 runtime uses an execution environment based on Ubuntu 18.04 with Node.js version 10.15.3. See Cloud Functions Execution Environment for more information.
The library that invokes your function is the Node Functions Framework.
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.
The Node.js 10 runtime automatically sets fewer environment variables than previous runtimes supported by Cloud Functions. For details, see Using Environment Variables.
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.