2

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

2
  • 1
    Your question is too broad. Please add some code if you tried something. If you didn't please do a google search and read some tutorials about firebase and cloud functions. Firebase doc is pretty good for explaining things. Check How to Ask to learn about good questions. Commented Sep 13, 2017 at 8:57
  • please check my code Commented Sep 13, 2017 at 9:10

1 Answer 1

3

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) => { ... })
Sign up to request clarification or add additional context in comments.

1 Comment

@harry please update your question with what you done and the complete error you get.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.