Firebase is back at Google I/O on May 10! Register now

Get started with Cloud Functions for Firebase (2nd gen)

Stay organized with collections Save and categorize content based on your preferences.

This page describes the steps you'll take to set up Cloud Functions for Firebase (2nd gen). If you're not already familiar with the general flow for setting up Cloud Functions for Firebase, refer to the 1st gen introduction and getting started guide.

Use a project on the Blaze plan

Because Cloud Functions for Firebase (2nd gen) 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 (2nd gen) 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 (2nd gen),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 (2nd gen) 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 1st gen SDK (optional)

The original Cloud Functions for Firebase SDK will now be known as 1st gen. You can still import the 1st gen SDK as previously. Or, to improve readability, you can now also import the 1st gen SDK from the v1 namespace.

const functions = require('firebase-functions/v1');
// alternatively:
// const functions = require('firebase-functions');

Functions written with the 1st gen SDK will be deployed to Cloud Functions 1st gen. To make it easier to migrate to 2nd gen, Cloud Functions allows a single codebase to contain both 1st gen and 2nd gen 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: