harry
harry

Reputation: 501

How to get data from firebase database using firebase cloud function http trigger

Hi I want to fetch data from firebase database using firebase cloud function http trigger. Is it possible using 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);

thanks

Upvotes: 2

Views: 1089

Answers (1)

bennygenel
bennygenel

Reputation: 24660

You can use Firebase Admin SDK to make database manipulations inside Cloud Functions.

Rather than using

functions.database.ref()

You can use

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) => { ... })

Upvotes: 3

Related Questions