Reputation: 1188
I have one problem to develop Firebase application. I wrote a HTTP trigger function to update database when it's triggered but not sure how to do it.
I think this is a quiet easy problem.
Thank you.
[EDIT]
exports.email = functions.https.onRequest((req, res) => {
functions.database.ref("test/appointment").once('value',(snapshots)=>{
console.log('value is',snapshots.val());
res.end()
})
});
I tried like above but it's not working.
Upvotes: 0
Views: 659
Reputation: 11326
As Doug mentioned in the comments, that's not valid.
If you want to access the database from your HTTP Triggered function, you'll need to you use the Server Admin SDK. Your code would look as follows:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.email = functions.https.onRequest((req, res) => {
const appointmentRef = admin.database().child('test/appointment');
appointmentRef.once('value',(snapshots)=>{
console.log('value is',snapshots.val());
res.end()
})
});
Upvotes: 1