Node.js Runtime Environment

The Node.js runtime is the software stack responsible for installing your web service's code and its dependencies and running your service. The Node.js runtime for App Engine in the standard environment is declared in the app.yaml file as nodejs8:

runtime: nodejs8

Node.js version

The Node.js runtime aims to use the latest release of Node.js 8 and the corresponding release of npm. App Engine automatically updates to new minor and patch releases, but will not automatically update the major version. For example, your application might be deployed at Node.js 8.9.4 and later automatically updated to version 8.10.0, but it will not be automatically updated to Node.js 10.x.x.

Because minor and patch versions are automatically updated, the engines.node property in your package.json file can only specify the major version:

{
  "engines": {
    "node": "8.x.x"
  }
}

The engines.node property is optional, but if present, the value must be compatible with Node.js 8. For example:

  • 8.x.x
  • ^8.0.0
  • ~8
  • >=6

If you specify an incompatible Node.js version in your package.json file, your deployment will fail with an error message.

Dependencies

During deployment, the runtime uses npm install to install the dependencies defined in your package.json and package-lock.json files. Because the runtime performs a fresh install, you do not need to upload your node_modules folder.

To support Node.js packages that require native extensions, the runtime includes system packages enabling you to use tools such as ImageMagick, FFmpeg, and Chrome headless. See the full list of packages at Included System Packages. To request a package, file an issue in the issue tracker.

Application startup

The runtime starts your application by using npm start, which uses the start script specified in your package.json file. For example:

"scripts": {
  "start": "node app.js"
}

For your app to receive HTTP requests, your start script should start a web server that listens on host 0.0.0.0 and the port specified by the PORT environment variable, which is accessible in Node.js as process.env.PORT.

For the best performance, the start script should be lightweight and exclude build steps, because it runs whenever a new instance of your application is created.

Environment variables

The following environment variables are set by the runtime:

Environment variable Description
GAE_APPLICATION The ID of your App Engine application.
GAE_DEPLOYMENT_ID The ID of the current deployment.
GAE_ENV The App Engine environment. Set to standard.
GAE_INSTANCE The ID of the instance on which your service is currently running.
GAE_MEMORY_MB The amount of memory available to the application process, in MB.
GAE_RUNTIME The runtime specified in your app.yaml file. The value is nodejs8 for Node.js.
GAE_SERVICE The service name specified in your app.yaml file. If no service name is specified, it is set to default.
GAE_VERSION The current version label of your service.
GOOGLE_CLOUD_PROJECT The GCP project ID associated with your application.
NODE_ENV Set to production when your service is deployed.
PORT The port that receives HTTP requests. Set to 8080.

You can define additional environment variables in your app.yaml file, but the above values cannot be overridden.

HTTPS and forwarding proxies

App Engine terminates HTTPS connections at the load balancer and forwards requests to your application. Some applications need to determine the original request IP and protocol. The user's IP address is available in the standard X-Forwarded-For header. Applications that require this information should configure their web framework to trust the proxy.

With Express.js, use the trust proxy setting:

app.set('trust proxy', true);

Filesystem

The runtime includes a full filesystem. The filesystem is read-only except for the location /tmp, which is a disk storing data in your App Engine instance's RAM.

Metadata server

Each instance of your application can use the App Engine metadata server to query information about the instance and your project.

The metadata server is accessible through either of the following hostnames:

  • http://metadata
  • http://metadata.google.internal

The following table lists the endpoints where you can make HTTP requests for specific metadata:

Metadata endpoint Description
/computeMetadata/v1/project/numeric-project-id The project number assigned to your project.
/computeMetadata/v1/project/project-id The project ID assigned to your project.
/computeMetadata/v1/instance/zone The zone the instance is running in.
/computeMetadata/v1/instance/service-accounts/default/aliases
/computeMetadata/v1/instance/service-accounts/default/email The default service account email assigned to your project.
/computeMetadata/v1/instance/service-accounts/default/ Lists all the default service accounts for your project.
/computeMetadata/v1/instance/service-accounts/default/scopes Lists all the supported scopes for the default service accounts.
/computeMetadata/v1/instance/service-accounts/default/token Returns the auth token that can be used to authenticate your application to other Google Cloud APIs.

For example, to retrieve your project ID, send a request to http://metadata.google.internal/computeMetadata/v1/project/project-id.

Was this page helpful? Let us know how we did:

Send feedback about...

App Engine standard environment for Node.js docs