Firebase cloud functions is similar to AWS lambda or serverless.

You can deploy you code which wrote in Node.js and deploy to firebase.

It can response for any realtime database changes or http requests.

Set up:

https://firebase.google.com/docs/functions/get-started

Code example:

For database changes:

// Listens for new messages added to /messages/:pushId/original and creates an
// uppercase version of the message to /messages/:pushId/uppercase
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
.onWrite(event => {
// Grab the current value of what was written to the Realtime Database.
const original = event.data.val();
console.log('Uppercasing', event.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return event.data.ref.parent.child('uppercase').set(uppercase);
});

For http request:

// Take the text parameter passed to this HTTP endpoint and insert it into the
// Realtime Database under the path /messages/:pushId/original
exports.addMessage = functions.https.onRequest((req, res) => {
// Grab the text parameter.
const original = req.query.text;
// Push the new message into the Realtime Database using the Firebase Admin SDK.
admin.database().ref('/messages').push({original: original}).then(snapshot => {
// Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
res.redirect(303, snapshot.ref);
});
});

[Firebase] Firebase Cloud Functions的更多相关文章

  1. Firebase Cloud Function 编写与部署

    1.设置和初始化 Firebase SDK for Cloud Functions (1).Cloud Functions 运行的是 Node v6.14.0,因此需要安装nodejs: https: ...

  2. Firebase Chat (firebase 实现web聊天室)

    基于firebase + cloud Function 实现web聊天(demo版) 知识点: 使用Firebase SDK创建Google Cloud功能. 触发云功能基于Auth,云存储和Clou ...

  3. 用 Flutter 和 Firebase 轻松构建 Web 应用

    作者 / Very Good Ventures Team 我们 (Very Good Ventures 团队) 与 Google 合作,在今年的 Google I/O 大会上推出了 照相亭互动体验 ( ...

  4. Firebase能改变什么(对SaaS,BaaS,PaaS,IaaS的解释比较清楚)

    作为Google Cloud对标Amazon AWS重要的一环,Firebase能改变什么? 雷锋网 2016-05-25 12:18:49 查看源网址 阅读数:12 按:本文作者刘之,野狗CEO.野 ...

  5. Angular 小试牛刀[2]:CI(travie+firebase)

    持续集成(Continuous Integration)是一种软件开发实践,即团队开发成员经常集成它们的工作,通过每个成员每天至少集成一次,也就意味着每天可能会发生多次集成.每次集成都通过自动化的构建 ...

  6. Expo大作战(十六)--expo结合firebase 一个nosql数据库(本章令我惊讶但又失望!)

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...

  7. [Firebase] 4. Firebase Object related Database

    The idea: This post we are going to learn how to build a Firebase Forage with object related databas ...

  8. [Firebase] 3. Firebase Simple Login Form

    Using $firebaseSimpleLogin service. Here we use three methods for login, logout, register and getCur ...

  9. google cloud storage products

    https://cloud.google.com/products/storage/ BigTable Cloud Bigtable 是 Google 面向大数据领域的 NoSQL 数据库服务.它也是 ...

随机推荐

  1. power design设计数据库

    power design是收费软件 大致设计流程: 画出概念数据模型,添加实体,连接实体间关系 生成物理数据模型,可以继续在此基础上修改 生成数据库脚本(一个.sql文件),文件中前面是删除表,后面是 ...

  2. CentOS 安装openssl

    https://blog.csdn.net/ydyang1126/article/details/72902113 安装环境: 操作系统:CentOS 7 OpenSSL Version:openss ...

  3. Object-C初体验

    前几周,看了书,标记了要Coding的例子.(书是写博客,CSDN送的,也可以用C币买) 周末,来搞几个例子. 2015年春,刚刚买Mac的时候,就搞了1个Object-C的HelloWorld,毕竟 ...

  4. 代码正常,junit却报错原因及解决方法

    junit测试,不能有参数 和static,去掉static测试正常;

  5. 彻底解决Linux索引节点(inode)占用率高的告警

    今天邮箱里发现有一封某服务器inode使用率发生告警的邮件 登录到服务器上df -i查看,发现/路径下91%,磁盘使用率却不高,猜测可能是某个目录下的小文件过多,进而造成inode占用率过高,但不清楚 ...

  6. CSUOJ 1644 超能陆战队

    1644: 超能陆战队 Time Limit: 1 Sec  Memory Limit: 256 MBSubmit: 6  Solved: 1[Submit][Status][Web Board] D ...

  7. NumPy基础入门学习

    对于习惯使用了MATLAB的用户而言,学习NumPy这个python工具包付出的成本应该是不大的. NumPy的基本的object是多维数组,是一个有同样类型的数字等构成的一张表格,能够通过元组进行索 ...

  8. 如何实现对网站页面访问量的统计(javaweb和php)

    如何实现对网站页面访问量的统计(javaweb和php) 一.总结 一句话总结:其实很简单啦,每访问一次那个页面对应的index函数(控制器中的那个函数)访问次数就加1就可以了. 1.javaweb中 ...

  9. js的类和继承

    因为我使用java语言入门的编程,所以对javascript的类和继承有种想当然一样,或者是差不多的感觉,但实际上两者还是有很多不同的 首先我们说类,javascript中类的实现是基于原型继承机制的 ...

  10. nodejs基础部分(一)

    前言 业余时间充实自我,入手学习了解一下传说中纯事件驱动/非阻塞的js架构 --nodejs 好记性不如烂笔头,本系列随笔用于整理记录学习nodejs过程中的心得 目录 nodejs简介 nodejs ...