Specifying dependencies

You specify the dependencies for your Node.js app by declaring them in the package.json file.

For example, if you want to specify Lodash as a dependency, your package.json file might look as follows:

{
  "dependencies": {
    "lodash": "^4.0.1"
  }
}

You can use any Linux-compatible Node.js package with App Engine flexible environment, including packages that require native (C) extensions.

During deployment, the Node.js runtime automatically installs all dependencies declared in your package.json file. By default, the npm install command is used, however Yarn and Pnpm package managers are also supported:

  • Yarn: If a yarn.lock file exists, the yarn install --production command is used instead.

  • Pnpm: Supported only by Node.js runtimes version 18 and version 20 (preview). If a pnpm-lock.yaml file exists, the pnpm install command is used instead.

Note that you must ensure that the yarn.lock or pnpm-lock.yaml file is not specified in the skip_files section of your app.yaml file.

Installing a web framework

You'll need to use a web framework to enable your app to serve web requests. You can use any Node.js web framework including the following:

To use a particular web framework, such as Express.js, add the framework to your package.json file:

  • Using npm:

    npm install --save express
  • Using yarn:

    yarn add express
  • Using pnpm:

    pnpm add express

For example, the resulting package.json file might look as follows:

{
  "dependencies": {
    "lodash": "^4.0.1",
    "express": "^4.16.2"
  }
}

Installing the Cloud Client Libraries

The Cloud Client Libraries for Node.js is the idiomatic way for Node.js developers to integrate with Google Cloud services, such as Firestore in Datastore mode (Datastore) and Cloud Storage.

To install the Node.js client library for Cloud Storage:

  1. Install the Cloud Client Libraries locally by using a package manager:

    • To use npm, run:

      npm install --save @google-cloud/storage
    • To use yarn, run:

      yarn add @google-cloud/storage
    • To use pnpm, run:

      pnpm add @google-cloud/storage
  2. Set up authentication. You can configure the Cloud Client Libraries for Node.js to handle authentication automatically.

  3. Use the Node.js client library for Cloud Storage reference to implement support for the Cloud Storage service in your app.