Specify dependencies in Node.js

A function is allowed to use external Node.js modules as well as local data. Dependencies in Node.js are managed with npm and expressed in a metadata file called package.json. You can use npm, yarn, pnpm, or Bun to install Node.js dependencies.

The Node.js Functions Framework is a required dependency for all functions. Although Cloud Run functions installs it on your behalf when the function is created, we recommend that you include it as an explicit dependency for clarity.

If your function relies on private dependencies, we recommend that you mirror functions-framework to your private registry. Include the mirrored functions-framework as a dependency to your function to avoid installing the package from the public internet.

To specify a dependency for your function, add it to your package.json file.

If the Node.js buildpack detects a lock file, such as package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lock, or bun.lockb within your project, it prioritizes that lock file when you install dependencies using npm ci, yarn install, pnpm install, or bun install.

The following example lists a dependency in the package.json file:

{
  "dependencies": {
    "escape-html": "^1.0.3"
  }
}

Cloud Run imports the dependency in the function:

const functions =