node.js - 如何使用firebase云函数http触发器从firebase数据库获取数据

标签 node.js firebase firebase-realtime-database google-cloud-functions

您好,我想使用 firebase 云函数 http 触发器从 firebase 数据库获取数据。是否可以使用functions.database.ref?

var functions = require('firebase-functions');
var cors = require("cors");
var express = require('express');
var http = require('http');

const app = express()
//~ app.use(cors({ origin: true }))
app.get("/", (request, response) => {
  response.send("Hello from Express on Firebase with CORS!")
})
app.get("/:id", (request, response) => {
     functions.database.ref('/Users/'+request.params.id)
})

    exports.httpFunction = functions.https.onRequest(app);

谢谢

最佳答案

您可以使用Firebase Admin SDK在 Cloud Functions 内进行数据库操作。

而不是使用

functions.database.ref()

您可以使用

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

// inside your triggered function
admin.database().ref('path/to/your/ref').on('value').then((snapshot) => { ... })

关于node.js - 如何使用firebase云函数http触发器从firebase数据库获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46192928/

相关文章:

javascript - 在 ES6 的 `import` 语法中,如何准确评估模块?

javascript - 关闭按钮未显示在 Bootstrap 可关闭警报上,但功能正常

android - 通过滑动删除 Firebase 对象

javascript - Firebase 类型错误 : Cannot read property 'val' of undefined

node.js - 将 nodejs 与 opsworks 一起使用时,console.XXX 的输出记录在哪里?

mysql - 获取列数据并插入到另一列中给出的 id 的行中 - sql nodejs

java - 查询后 Firebase 获取子值

firebase - 如何在 Firebase 身份验证中限制电子邮件域

swift - 某些数据未从 Firebase 数据库 Swift 3 中读取

javascript - Firebase 关键引用