Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

functions-samples

> 数据库
Open source

Collection of sample apps showcasing popular use cases using Cloud Functions for Firebase

12.2K stars0 likes2 views
WebsiteGitHub

About

Collection of sample apps showcasing popular use cases using Cloud Functions for Firebase

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

  • Node 2nd gen
  • Python
  • Node 1st gen

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

  • Dart
  • Node 2nd gen
  • Python
  • Node 1st gen

Quickstart: Stream responses with callable functions

  • Dart
  • Node 2nd gen

HTTPS trigger quickstart: Time Server

  • Dart
  • Node 2nd gen
  • Python
  • Node 1st gen

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

  • Node 2nd gen
  • Python
  • Node 1st gen

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

  • Node 1st gen

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

  • Node 2nd gen
  • Python
  • Node 1st gen

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

  • Node 2nd gen
  • Node 1st gen

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

  • Node 2nd gen
  • Python
  • Node 1st gen

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

  • Node 2nd gen
  • Python
  • Node 1st gen

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

  • Node 2nd gen
  • Python

Firebase Alerts trigger quickstart: Send crash reports to Discord

  • Node 2nd gen
  • Python
  • Node 1st gen: not supported

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

  • Node 2nd gen
  • Python
  • Node 1st gen: not supported

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

Unit testing

  • Test with Jest
    • Test with Jest and TypeScript
  • Test with Mocha

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

  • Node (1st gen)

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

  • Node (1st gen)

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

  • Node (1st gen)

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

Moderate offensive images

  • Node (1st gen)

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

  • Node (1st gen)

Demonstrates how to automatically extract image's metadata using ImageMagick for images that are uploaded to Firebase Storage. Uses a Firebase Storage trigger.

Task Queues: back up images from an API

  • Node 2nd gen
  • Python

See how to use Task Queues to meter traffic to a rate-limited API.

Firebase Realtime Database Data Consistency

These samples show how to implement automatic data consistency such as keeping a count of children, having a max amount of node childs, cleaning up old data etc...

LastModified Firebase Realtime Database tracking

  • Node (1st gen)

Tracking when the Firebase Database (or a subset) was last modified. Uses a Realtime Database trigger.

Firebase Database child nodes count

  • Node (1st gen)

Keeps track of the number of child nodes of a Firebase Database element allowing clients to filter or order results using the child count. This can be useful to keep track of the number of "likes" or "followers" of something shared through social media. Uses a Realtime Database trigger.

Limit number of child nodes

  • Node (1st gen)

Makes sure that the number of child nodes stays below a certain threshold. This can be useful to limit the number of lines of logs or chat history below a given number. Uses a Realtime Database trigger.

Removing old items from a list

  • Node (1st gen)

This sample shows how to remove child nodes older than 2 hours from a Firebase Database list. This can be useful for removing outdated items from a collection. Uses a Realtime Database trigger.

Solve other common use cases

Send FCM notifications

  • Node (1st gen)

This sample demonstrates how to send a Firebase Cloud Messaging (FCM) notification from a Realtime Database triggered Function when users get new followers. The sample also features a Web UI to experience the FCM notification. Uses a Realtime Database trigger.

Google Assistant says ordinal of given number

  • Node (1st gen)

This sample shows how to create an action for the Google Home/Assistant using the Actions SDK hosted on Cloud Functions. The sample action asks users to say a number and reads out the ordinal of that number. Uses an HTTP trigger.

Authenticated JSON API

  • Node (1st gen)

This sample shows how to authenticate access to a JSON API to only allow access to data for a specific Firebase user. Uses an HTTP trigger.

Authorized HTTP endpoint

  • Node (1st gen)

This sample shows how to restrict an HTTPS Function to only the Firebase users of your app. Only users who pass a valid Firebase ID token as a Bearer token in the Authorization header of the HTTP request or in a __session cookie are authorized to use the function. Checking the ID token is done with an ExpressJs middleware that also passes the decoded ID token in the Express request object. Uses an HTTP trigger.

Authorize with 3rd-party authentication providers

Okta, LinkedIn, Spotify, Instagram, or Basic Auth

Demonstrates how to authorize with a 3rd party sign-in mechanism, create a Firebase custom auth token, update the user's profile and authorize Firebase. Uses an HTTP trigger.

Post GitHub commits to Slack channel

  • Node (1st gen)

Demonstrates how to automatically post GitHub commits to a Slack channel using an HTTPS triggered Function.

Create and charge customers with Stripe or Paypal

Demonstrates hows to integrate Firebase Auth and the Realtime database with Stripe via the Stripe Node.js library and shows how to create HTTP endpoints to charge customers via Paypal.

Text moderation

  • Node (1st gen)

Demonstrates how to moderate user input text for bad words. This can be used to moderate usernames, chat or forum messages. Uses a Realtime Database trigger.

Issues· 155 open

View all issuesOpen on GitHub
  • #1025

    [DOCS] for sample: /quickstarts/email-users

    Updated Sep 17, 2026
  • #1032

    [DOCS] cloud_functions onCall : How can I get idToken ?

    Updated Feb 8, 2026
  • #1136

    [BUG] Firebase Functions Tasks: Firebase ID token has incorrect "aud" (audience) claim.

    type: bugUpdated Jun 6, 2025
  • #1129

    [DOCS] for sample: auth-blocking-functions | Cannot extract event_type

    Updated Jan 24, 2025
  • #1159

    [DOCS] https://firebase.google.com/docs/firestore/solutions/presence#updating_globally not correct example

    Updated Nov 8, 2024
  • #336

    Please add example for generate pdf from html

    type: feature requesthelp wantedUpdated Sep 2, 2024
  • #1061

    [DOCS] Example app in readme.md does not work

    Updated Jul 18, 2024
  • #1154

    [BUG] in sample: Spotify Auth

    type: bugUpdated Jul 14, 2024
  • #1143

    [BUG] in sample: taskqueues-backup-images

    type: bugUpdated Jun 21, 2024
  • #1137

    https_fn.HttpsError::message isn't really surfaced

    Updated Jun 2, 2024

> Tags

JavaScriptfaasfaas-platformfirebasegoogle

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 28, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库