This page describes the steps you'll take to set up Cloud Functions for Firebase v2. If you're not already familiar with the general flow for setting up Cloud Functions for Firebase, refer to the v1 introduction and getting started guide.
Use a project on the Blaze plan
Because Cloud Functions for Firebase v2 runs on Cloud Run, you'll need to provide a billing instrument to get started. Cloud Run has a free tier of 2 million requests per month. View more details at Cloud Run pricing.
Install the SDK
The Cloud Functions for Firebase v2 library is available on npm. All of the work done on the library is also public on GitHub.
To to enable Cloud Functions for Firebase v2, run the following commands in the Firebase CLI:
# Install the latest version of the Firebase CLI
npm install -g firebase-tools
# Initialize a project, if necessary
firebase init functions
Import the firebase-functions
SDK
The Cloud Functions for Firebase v2 SDK is in the v2
package export.
You can import subpackages (recommended), or you can import a monolith at
firebase-functions/v2
as shown:
// import from a specific subpackage
const {onRequest} = require('firebase-functions/v2/https');
// import the entire v2 monolith
const functionsV2 = require('firebase-functions/v2');
Import the v1 SDK (optional)
The original Cloud Functions for Firebase SDK will now be known as v1. You can
still import the v1 SDK as previously. Or, to improve readability, you can now
also import the v1 SDK from the v1
namespace.
const functions = require('firebase-functions/v1');
// alternatively:
// const functions = require('firebase-functions');
Functions written with the v1 SDK will be deployed to Cloud Functions v1. To make it easier to migrate to v2, Cloud Functions allows a single codebase to contain both v1 and v2 functions.
Next steps
See the guides and sample code for each supported trigger type, including the new types, Firebase Alerts triggers, custom event triggers for Firebase Extensions, and task queue functions. Also see the fundamental guidance on how to: