Skip to content

Cloud Functions for Firebase Sample Library

This repository contains a collection of samples showcasing some typical uses of Cloud Functions for Firebase.

Samples are available for Node (1st and 2nd gen) and Python (2nd gen).

Note: Python support in Cloud Functions for Firebase is a public preview. This means that the functionality might change in backward-incompatible ways. A preview release is not subject to any SLA or deprecation policy and may receive limited or no support.

What's Cloud Functions for Firebase?

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

Prerequisites

All samples require the Blaze pay-as-you-go billing plan to deploy. Learn more about pricing.

To learn how to get started with Cloud Functions for Firebase by having a look at the Getting Started Guide, trying the quickstart samples and looking at the documentation.

Quickstarts

Minimal samples for each Cloud Functions trigger type.

Quickstart: Uppercaser for Firestore

This quickstart sample demonstrates using Cloud Functions triggered by Firestore events. The function transforms message text written to Firestore to uppercase.

Quickstart: Add numbers and sanitize text with callable functions

Quickstart: Stream responses with callable functions

HTTPS trigger quickstart: Time Server

This quickstart sample demonstrates using Cloud Functions triggered by HTTPS requests. The function returns the current server time and allows for date time formatting.

Quickstart: Uppercaser for Realtime Database

This quickstart sample demonstrates using Cloud Functions triggered by Realtime Database events. The function transforms message text written to Realtime Database to uppercase.

Hosting triggered HTTPS function quickstart: Big Ben

This quickstart demonstrates using Cloud Functions with an HTTPS trigger that's triggered by a Firebase Hosting URL. The function will display a repeated number of "BONG"s depending on the hour of the day.

Cloud Storage trigger quickstart: Thumbnail generator

This quickstart sample demonstrates using Cloud Functions triggered by Firebase Storage events. The function generates a thumbnail of uploaded images.

Auth trigger quickstart: Welcome Email

This quickstart sample demonstrates using Cloud Functions triggered by Firebase Auth events. The function sends a Welcome Email when user accounts are created (or when users sign-in using an Identity Provider for the first time) and sends a Goodbye Email when user accounts are deleted.

Auth blocking trigger quickstart: Validate and check user status

This quickstart demonstrates using Auth blocking functions to validate a user's email before they are allowed to sign in, and to see if a user is part of a list of banned users in Firestore.

PubSub trigger quickstart: Hello World

This quickstart sample demonstrates using Cloud Functions triggered by PubSub events. The functions log the PubSub payload in a Hello world message.

Test Lab trigger quickstart: Log when a matrix completes

Firebase Alerts trigger quickstart: Send crash reports to Discord

Trigger a function based on a Firebase Alert, and send information about the alert to a channel in a Discord server.

Custom Events: Save image metadata

Learn how to trigger a function based on an event sent by an extension

Unit testing

Development Boilerplates

The Firebase CLI generates sample code for Cloud Functions using JavaScript or TypeScript.

Server-side generated pages w/ Handlebars templating and user sessions

This sample shows how to serve server-side generated HTML pages using the HandlebarsJs templating system and serve user-specific content by always passing the Firebase ID token in a __session cookie.

Image Processing

Here are a few samples that show how you can process or analyze images using Cloud Functions.

Image Maker

This sample demonstrates how to create various customized images such as sparkline or sphere charts through Cloud Functions and Hosting and serve it to the client. Uses an HTTP trigger.

Convert images after upload

Demonstrates how to automatically convert images that are uploaded to Firebase Storage to JPEG using ImageMagick. Uses a Firebase Storage trigger.

Moderate offensive images

Demonstrates how to automatically moderate offensive images that are uploaded to Firebase Storage by using the Google Cloud Vision API to detect offensive images and ImageMagick to blur these images. Uses a Firebase Storage trigger.

Extract image metadata