Managing Node.js function dependencies
Cloud Functions can automatically install dependencies required for a Node.js function to run when creating a new function version.
To install dependencies, use the npm ci --production command that runs in the project root (function directory). This installs only the primary dependencies. It will not install the development dependencies from the devDependencies section.
You can list the required libraries in the following ways:
-
Upload
package.jsonandpackage-lock.jsonwith the function code so Cloud Functions can automatically install dependencies.If you do not upload
package-lock.json, thenpm i --productioncommand will be executed instead ofnpm ci --production, and the function will take longer to initialize. -
Add all the required dependencies to a single file yourself using a code bundler, such as
webpack, or uploadnode_moduleswith the function code.
The dependency installation process has some technical restrictions. For more information, see Quotas and limits in Cloud Functions. You can view the dependency installation log using the link that appears in the list of operations.