This repository contains a collection of samples showcasing some typical uses of Cloud Functions for Firebase.
All samples use the Node 14 runtime and require the Blaze pay-as-you-go billing plan to deploy. Learn more about Cloud Functions for Firebase's Node versions here.
Cloud Functions is a hosted, private, and scalable Node.js environment where you can run JavaScript 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.
To learn how to get started with Cloud Functions for Firebase by having a look at our Getting Started Guide, trying the quickstart samples and looking at the documentation.
This repository contains a few categories of samples:
Here is a set of minimal samples for each Cloud Functions trigger types.
This quickstart sample demonstrates using Cloud Functions triggered by Firebase Realtime Database or 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 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.
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 sample demonstrates using Cloud Functions triggered by PubSub events. The functions log the PubSub payload in a Hello world message.
This quickstart demonstrates how to trigger a function in response to thecompletion of a test matrix in Firebase Test Lab.
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 generate a thumbnail for images that are uploaded to Firebase Storage using ImageMagick and generate a public download link for the images.Uses a Firebase Storage trigger.
Demonstrates how to use Node.js Stream to read image from Cloud Storage, generate a thumbnail image using Sharp and upload it back to Cloud Storage.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.
Demonstrates how to automatically extract image's metadata using ImageMagick for images that are uploaded to Firebase Storage.Uses a Firebase Storage trigger.
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...
Tracking when the Firebase Database (or a subset) was last modified.Uses a Realtime Database trigger.
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.
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.
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.
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.
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.
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.
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.
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.
Demonstrates how to automatically post GitHub commits to a Slack channel using an HTTPS triggered Function.
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.
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.
Sends email confirmation after users subscribed to a mailing list.Uses a Realtime Database trigger.
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.
Integrates the Bit.ly API to shorten URLs automatically as they are added to the database.Uses a Realtime Database trigger.
Enable full-text search on Firebase Database data or Firestore documents by using a hosted search service.Uses a Realtime Database or Firestore trigger.
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 athttps://github.com/firebase/user-data-protection
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.
Copies Firebase Database elements into BigQuery automatically. This can be useful for instance for further logs analysis.Uses a Realtime Database trigger.
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.
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.
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.
Periodically deletes the accounts of users who have not signed in in the last month.Uses an HTTPS trigger.
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.
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.
Build a simple online / offline status indicator for your users by leveraging Firestore and Realtime Database together.Uses a Realtime Database trigger.
Automatically publishes models to Firebase ML for each TensorFlow Lite file that is uploaded to Firebase Storage.
This sample shows how to query the Youtube Data API.Uses an HTTPS trigger.
We'd love that you contribute to the project. Before doing so please read our Contributor guide.
© Google, 2015-2020. Licensed under an Apache-2 license.
简介 Simple Reference 基础CUDA示例,适用于初学者, 反映了运用CUDA和CUDA runtime APIs的一些基本概念. Utilities Reference 演示如何查询设备能力和衡量GPU/CPU 带宽的实例程序。 Graphics Reference 图形化示例展现的是 CUDA, OpenGL, DirectX 之间的互通性 Imaging Referenc
The use of functions provides many benefits, including: The code inside the function can be reused. It is much easier to change or update the code in a function (which needs to be done once) than for
STM32 Alternate functions 与 Additional functions STM32 MCU的IO引脚可以作为GPIO功能(绝大部分IO上电后的默认为该模式),也可以作为Alternate functions(复用功能)和 Additional functions(附加功能、辅助功能)。 Alternate functions:Functions selected thro
一、日期格式说明 类型 说明 Cc 两位数字的世纪 scc 有负号的两位数字的世纪,表示世纪前 Q 表示一位数季度 yyyy 表示4位数年 iyyy 表示4位数年,ISO格式 rrrr 表示当前年的4位数字的圆整年 y,yyy 有逗号的4位数字年 Yyy 年的最后3位数字 Yy 年的最后2位数字 Iyy 年的最后2位数字,ISO格式 Rr 基于当前年的两位数字的圆整年 Y 年的最后1位数字 I 年
Python functions 记录了一些在写代码时遇到的python函数,主要集中在numpy库 numpy.argsort(a, axis=-1, kind=‘quicksort’, order=None) 排序,返回下标 Examples: One dimensional array: >>> x = np.array([3, 1, 2]) >>> np.argsort(x) array(
When a function is invoked as a function rather that as a method, the this keyword refers to the global object. Confusingly, this is true even when a nested function is invoked (as a function) within
harmonic functions factorial functions bounding http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/readings/l11_sums
Number Methods Number对象仅包含属于每个对象定义的默认方法。 Sr.No 方法和描述 1 constructor() 返回创建此对象实例的函数。 默认情况下,这是Number对象。 2 toExponential() 强制数字以指数表示法显示,即使该数字在JavaScript通常使用标准表示法的范围内。 3 toFixed() 格式化小数点右侧具有特定位数的数字。 4 toLo
函数是一组可重用的代码,可以在程序中的任何位置调用。 这消除了一次又一次地编写相同代码的需要。 它可以帮助程序员编写模块化代码。 函数允许程序员将大程序划分为许多小而易于管理的函数。 与任何其他高级编程语言一样,JavaScript也支持使用函数编写模块化代码所需的所有功能。 您必须在前面的章节中看到过alert()和write()等函数。 我们一次又一次地使用这些函数,但它们只用核心JavaSc
函数是有组织的可重用代码块,用于执行单个相关操作。 函数为您的应用程序提供了更好的模块化,并且可以高度重用代码。 如您所知,Python为您提供了许多内置函数,如print()等,但您也可以创建自己的函数。 这些函数称为user-defined functions. 定义一个函数 (Defining a Function) 您可以定义函数以提供所需的功能。 以下是在Python中定义函数的简单规则
函数是一组一起执行任务的语句。 在MATLAB中,函数在单独的文件中定义。 文件和函数的名称应该相同。 函数对自己工作空间中的变量进行操作,该工作空间也称为local workspace ,与您在MATLAB命令提示符(称为base workspace访问的工作local workspace分开。 函数可以接受多个输入参数,并且可以返回多个输出参数。 函数语句的语法是 - function [ou
Creates a Sequence consisting of the keys from this sequence whose values are functions. Signature ObjectLikeSequence.functions = function() { /*...*/ } ObjectLikeSequence.functions = function functio
因为underscore本来就是为了充分发挥JavaScript的函数式编程特性,所以也提供了大量JavaScript本身没有的高阶函数。 bind bind()有什么用?我们先看一个常见的错误用法: 'use strict'; var s = ' Hello '; s.trim(); // 输出'Hello' var fn = s.trim; fn(); // Uncaught TypeE