Cloud Functions for Firebase

Cloud Functions is a hosted, private, and scalable Node.js environment where you can run JavaScript code. Firebase SDK for Cloud Functions integrates the Firebase platform by letting you write code that responds to events and invokes functionality exposed by other Firebase features.

Already using Cloud Functions on Google Cloud Platform? Learn more about how Firebase fits into the picture.

Get Started USE CASES

Key capabilities

Integrates the Firebase platform The functions you write can respond to events generated by these other Firebase and Google Cloud features:

You can integrate with third-party services by writing your own webhooks. Functions minimizes boilerplate code, making it easier to use Firebase and Google Cloud inside your function.
Zero maintenance Deploy your code to our servers with one command from the command line. After that, Firebase automatically scales up computing resources to match the usage patterns of your users. You never worry about credentials, server configuration, provisioning new servers, or decommissioning old ones.
Keeps your logic private and secure In many cases, developers prefer to control application logic on the server to avoid tampering on the client side. Also, sometimes it’s not desirable to allow that code to be reverse engineered. Cloud Functions is fully insulated from the client, so you can be sure it is private and always does exactly what you want.

How does it work?

After you write and deploy a Cloud Function, Google’s servers begin to manage the function immediately, listening for events and running the function when it is triggered. As the load increases or decreases, Google responds by rapidly scaling the number of virtual server instances needed to run your function.

Lifecycle of a Cloud Function for Firebase

  1. The developer writes code for a new Cloud Function, selecting an event provider (such as Realtime Database), and defining the conditions under which the Cloud Function should execute.
  2. The developer deploys the Cloud Function, and Firebase connects it to the selected event provider.
  3. When the event provider generates an event that matches the Cloud Function's conditions, the code is invoked.
  4. If the Cloud Function is busy handling many events, Google creates more instances to handle work faster. If the Cloud Function is idle, instances are cleaned up.
  5. When the developer updates the Cloud Function by deploying updated code, all instances for the old version are cleaned up and replaced by new instances.
  6. When a developer deletes the Cloud Function, all instances are cleaned up and the connection between the Cloud Function and the event provider is removed.

Implementation path

Set up Functions Install the Firebase CLI and initialize Cloud Functions in your Firebase project.
Write functions Write JavaScript code to handle events from Firebase services, Google Cloud services, or other event providers.
Deploy and monitor Deploy your functions using the Firebase CLI. You can use the Firebase console to view and search through your logs.

Next steps

Send feedback about...

Need help? Visit our support page.