Migrating Cloud Functions to newer Node.js runtimes

The Node.js 6 runtime has been deprecated. To ensure that your functions are on a supported version of Node.js, migrate them to Node.js 8 or Node.js 10. After 2020-04-22, function deployments that use Node.js 6 will be blocked. Cloud Functions that continue to use Node.js 6 after this time may be disabled.

The Node.js 8 and Node.js 10 runtimes introduced changes that might require you to modify your function's source code to use the newer runtimes. This page describes the changes and provides guidelines for migrating existing functions to newer runtimes.

Changes introduced in the Node.js 8 runtime

The signature for background functions changed between the Node.js 6 and the Node.js 8 runtimes.

An example Node.js 6 background function might look as follows:

exports.nodejs6BackgroundFunction = (event, callback) => {
  let data = event.data;
  let context = event.context;
  // ... the rest of your function
};

Note that the event argument contains data and context properties. Starting in the Node.js 8 runtime, the data and context properties have been extracted from the event object and are now included as part of the function signature:

exports.nodejs8AndAboveBackgroundFunction = (data, context, callback) => {
  // ... the rest of your function is unchanged
};

This change simplifies references to the data and context objects previously contained within the event argument. For more information, see Background function parameters.

If you are using the Node.js 6 background function signature, make the following changes to run your function in a newer Node.js runtime:

  1. Change the function signature from (event, callback) to (data, context, callback).

  2. Change references to event.data and event.context to data and context, respectively.

Changes introduced in the Node.js 10 runtime

On top of the changes introduced in the Node.js 8 runtime, the Node.js 10 runtime introduced changes to the environment variables that are predefined by the runtime. See Environment variables set automatically for a full description of the differences between environment variables set by the Node.js 10 runtime versus previous runtimes.

To run your older Node.js functions in the Node.js 10 runtime, you might need to make changes to any predefined environment variables you are using. Update your code to use the replacement variables where possible or set them yourself when deploying your function. As a best practice, we recommend that you do not depend on environment variables that you have not set explicitly.

The following environment variables are no longer set by the Node.js 10 runtime:

Environment variable Migration
CODE_LOCATION Set it when deploying your function. Your code location is /srv.
ENTRY_POINT Use the FUNCTION_TARGET environment variable instead.
GOOGLE_CLOUD_PROJECT Set it when deploying your function.
GCP_PROJECT Set it when deploying your function.
GCLOUD_PROJECT Set it when deploying your function.
GOOGLE_CLOUD_REGION Set it when deploying your function.
FUNCTION_REGION Set it when deploying your function.
FUNCTION_NAME Use the K_SERVICE environment variable instead.
FUNCTION_IDENTITY Set it when deploying your function.
FUNCTION_MEMORY_MB Set it when deploying your function.
FUNCTION_TIMEOUT_SEC Set it when deploying your function.
FUNCTION_TRIGGER_TYPE Use the FUNCTION_SIGNATURE_TYPE environment variable instead. See Using environment variables for usage details.
OLDPWD No longer available.
SHLVL No longer available.
Bu sayfayı yararlı buldunuz mu? Lütfen görüşünüzü bildirin:

Şunun hakkında geri bildirim gönderin...

Cloud Functions Documentation