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.
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.
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.
Minimal samples for each Cloud Functions trigger type.
This quickstart sample demonstrates using Cloud Functions triggered by Firestore events. The function transforms message text written to Firestore to uppercase.
This quickstart sample demonstrates using Cloud Functions triggered by HTTPS requests. The function returns the current server time and allows for date time formatting.
This quickstart sample demonstrates using Cloud Functions triggered by Realtime Database events. The function transforms message text written to Realtime Database to uppercase.
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.
This quickstart sample demonstrates using Cloud Functions triggered by Firebase Storage events. The function generates a thumbnail of uploaded images.
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.
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.
This quickstart sample demonstrates using Cloud Functions triggered by PubSub events. The functions log the PubSub payload in a Hello world message.
- 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.
- Node 2nd gen
- Python
- Node 1st gen: not supported
Learn how to trigger a function based on an event sent by an extension
The Firebase CLI generates sample code for Cloud Functions using JavaScript or TypeScript.
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.
Here are a few samples that show how you can process or analyze images using Cloud Functions.
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.
Demonstrates how to automatically convert images that are uploaded to Firebase Storage to JPEG using ImageMagick. Uses a Firebase Storage trigger.
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.