• Stars
    star
    12,063
  • Rank 2,717 (Top 0.06 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated 22 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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 the Node (2nd gen), Python (2nd gen), and Node (1st 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

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 through 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

Auth user create and delete triggers aren't yet supported by 2nd gen functions

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](/2nd-gen/alerts-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

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

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

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

Firebase Database child nodes count

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

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

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

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

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

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

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

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

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.

Email confirmation

Sends email confirmation after users subscribed to a mailing list. Uses a Realtime Database trigger.

Automatic message translation

Integrates the Google Translate API to perform automatic text translation across any number of languages. Language codes can be stored in Firebase for on the fly changes. Uses a Realtime Database trigger.

Automatic URL shortener

Integrates the Bit.ly API to shorten URLs automatically as they are added to the database. Uses a Realtime Database trigger.

Full-text search for Realtime Database or Firestore

Enable full-text search on Firebase Database data or Firestore documents by using a hosted search service. Uses a Realtime Database or Firestore trigger.

User data cleanup

Deletes all associated user data in the Realtime database when a user deletes his Firebase account. Uses an Auth trigger. This code has moved to its own repo at https://github.com/firebase/user-data-protection

Export your data to a Google Spreadsheet

This sample demonstrates how to sync new data written to a Firebase database to a Google Sheet. It includes a method for obtaining, storing, and using Oauth2 tokens for Google API access. Uses HTTPS triggers and Realtime Database triggers.

Export your data to Big Query

Copies Firebase Database elements into BigQuery automatically. This can be useful for instance for further logs analysis. Uses a Realtime Database trigger.

Webhook upon Firebase Database writes

Writing to the Firebase Database triggers a request to a callback URL (a Webhook). The content of the modified Data is sent to the Webhook. Uses a Realtime Database trigger.

Send a survey when users update your app

This sample shows how to send a survey to your users who have updated your app. App Update is detected using a Firebase Analytics event. Uses an Analytics trigger.

Send a coupon to user who have completed a purchase

This sample shows how to send a coupon to your users who have just purchased something. 10% off on your next purchase! Uses an Analytics trigger.

Delete inactive users accounts via cron

Periodically deletes the accounts of users who have not signed in in the last month. Uses an HTTPS trigger.

Developer Motivator

This sample demonstrates how to send a Firebase Cloud Messaging (FCM) notification to the developer device each time your app gains or loses a user. Uses an Analytics trigger.

Audio Files Conversion

This sample uses ffmpeg / fluent-ffmpeg and automatically converts audio files that are uploaded to Cloud Storage to FLAC file format with mono-channel audio @ 16000hz. Uses a Storage trigger.

Presence for Firestore

Build a simple online / offline status indicator for your users by leveraging Firestore and Realtime Database together. Uses a Realtime Database trigger.

Publish Models to Firebase ML

Automatically publishes models to Firebase ML for each TensorFlow Lite file that is uploaded to Firebase Storage.

Get information about a YouTube channel

This sample shows how to query the Youtube Data API. Uses an HTTPS trigger.

Contributing

We'd love that you contribute to the project. Before doing so please read our Contributor guide.

License

© Google, 2015-2023. Licensed under an Apache-2 license.

Build Status

Actions Status

More Repositories

1

flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
Dart
8,671
star
2

quickstart-android

Firebase Quickstart Samples for Android
Java
8,563
star
3

firebase-js-sdk

Firebase Javascript SDK
TypeScript
4,830
star
4

quickstart-js

Firebase Quickstart Samples for Web
HTML
4,818
star
5

FirebaseUI-Android

Optimized UI components for Firebase
Java
4,628
star
6

firebaseui-web

FirebaseUI is an open-source JavaScript library for Web that provides simple, customizable UI bindings on top of Firebase SDKs to eliminate boilerplate code and promote best practices.
JavaScript
4,558
star
7

firebase-tools

The Firebase Command Line Tools
TypeScript
3,994
star
8

firebase-ios-sdk

Firebase iOS SDK
Objective-C
3,583
star
9

quickstart-ios

Firebase Quickstart Samples for iOS
Swift
2,773
star
10

firebase-android-sdk

Firebase Android SDK
Java
2,244
star
11

codelab-friendlychat-web

The source for the Firebase codelab for building a cross-platform chat app
JavaScript
1,749
star
12

firebase-admin-node

Firebase Admin Node.js SDK
TypeScript
1,621
star
13

FirebaseUI-iOS

iOS UI bindings for Firebase.
Objective-C
1,507
star
14

geofire-js

GeoFire for JavaScript - Realtime location queries with Firebase
TypeScript
1,443
star
15

firebaseui-web-react

React Wrapper for firebaseUI Web
JavaScript
1,262
star
16

firebase-admin-go

Firebase Admin Go SDK
Go
1,142
star
17

superstatic

Superstatic: a static file server for fancy apps.
JavaScript
1,097
star
18

firebase-functions

Firebase SDK for Cloud Functions
TypeScript
1,024
star
19

firebase-admin-python

Firebase Admin Python SDK
Python
1,019
star
20

quickstart-nodejs

JavaScript
895
star
21

extensions

Source code for official Firebase extensions
TypeScript
892
star
22

quickstart-unity

Firebase Quickstart Samples for Unity
C#
775
star
23

snippets-android

Android snippets for firebase.google.com
Java
762
star
24

snippets-web

Web snippets for firebase.google.com
JavaScript
749
star
25

genkit

An open source framework for building AI-powered apps with familiar code-centric patterns. Genkit makes it easy to develop, integrate, and test AI features with observability and evaluations. Genkit works with various models and platforms.
TypeScript
701
star
26

geofire-java

GeoFire for Java - Realtime location queries with Firebase
Java
671
star
27

firebase-admin-java

Firebase Admin Java SDK
Java
527
star
28

friendlyeats-web

JavaScript
467
star
29

geofire-objc

GeoFire for Objective-C - Realtime location queries with Firebase
Objective-C
440
star
30

snippets-node

Node.js snippets for firebase.google.com
JavaScript
369
star
31

firebase-admin-dotnet

Firebase Admin .NET SDK
C#
367
star
32

quickstart-testing

Samples demonstrating how to test your Firebase app
TypeScript
335
star
33

firebase-tools-ui

A local-first UI for Firebase Emulator Suite.
TypeScript
269
star
34

friendlyeats-android

Cloud Firestore Android codelab
Kotlin
261
star
35

codelab-friendlychat-android

Firebase FriendlyChat codelab
Kotlin
243
star
36

firebase-cpp-sdk

Firebase C++ SDK
C++
230
star
37

quickstart-java

Quickstart samples for Firebase Java Admin SDK
Java
224
star
38

firebase-functions-test

TypeScript
211
star
39

quickstart-cpp

Firebase Quickstart Samples for C++
C++
190
star
40

fastlane-plugin-firebase_app_distribution

fastlane plugin for Firebase App Distribution. https://firebase.google.com/docs/app-distribution
Ruby
166
star
41

friendlypix-ios

Friendly Pix iOS is a sample app demonstrating how to build an iOS app with the Firebase Platform.
Swift
166
star
42

quickstart-flutter

Dart
138
star
43

firebase-functions-python

Python
136
star
44

geofire-android

GeoFire for Android apps
Java
133
star
45

firebase-unity-sdk

The Firebase SDK for Unity
C#
128
star
46

friendlyeats-ios

Swift
127
star
47

snippets-ios

iOS snippets used in firebase.google.com
Objective-C
121
star
48

firebaseopensource.com

Source for firebase open source site
TypeScript
118
star
49

quickstart-python

Jupyter Notebook
115
star
50

FirebaseUI-Flutter

Dart
102
star
51

codelab-friendlychat-ios

Swift
68
star
52

snippets-rules

Snippets for security rules on firebase.google.com
TypeScript
45
star
53

emulators-codelab

JavaScript
44
star
54

oss-bot

Robot friend for open source repositories
TypeScript
36
star
55

firebase-bower

Firebase Web Client
JavaScript
35
star
56

snippets-flutter

Dart
30
star
57

snippets-go

Golang snippets for firebase docs
Go
24
star
58

snippets-java

Java snippets for firebase.google.com
Java
17
star
59

firebase-docs

TypeScript
16
star
60

abseil-cpp-SwiftPM

C++
13
star
61

firebase-testlab-instr-lib

Java
13
star
62

snippets-cpp

C++ snippets for firebase.google.com
C++
12
star
63

SpecsStaging

SpecsStaging
11
star
64

SpecsTesting

Ruby
11
star
65

rtdb-to-csv

JavaScript
11
star
66

appquality-codelab-ios

Firebase iOS App Quality Codelab
Objective-C
11
star
67

level-up-with-firebase

C#
9
star
68

boringSSL-SwiftPM

C++
8
star
69

firestore-bundle-builder

TypeScript
7
star
70

.github

Default configuration for Firebase repos
6
star
71

nginx

This repo is a PUBLIC FORK
C
6
star
72

SpecsDev

6
star
73

snippets-python

Python snippets for firebase.google.com
4
star
74

firebase-release-dashboard

JavaScript
4
star
75

ok

HTTPS CDN Proxy Healthy Check
4
star
76

grpc-SwiftPM

C++
3
star
77

crashlytics-testapps

Java
2
star
78

data-connect-ios-sdk

Swift
2
star
79

.allstar

1
star