I am new to firebase but when I deploy my functions and execute onWrite()
method this is the error I get:
ReferenceError: firebase is not defined at exports.sendJobNotification.functions.database.ref.onWrite.event (/user_code/index.js:11:3) at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:35:20 at process._tickDomainCallback (internal/process/next_tick.js:135:7)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendPaymentNotification = functions.database.ref('payments/{paymentID}').onWrite(event => {
if (event.data.previous.exists()) {
return;
}
firebase.database().ref('payments').child(event.params.paymentID).once('value').then(function(snap){
var jobData = snap.val();
console.log(jobData)
});
});
This means that you didn't include the Firebase JavaScript library in your page yet. Instead of starting from a blog post, I recommend that you start with this 5-minute interactive tutorial. It explains what to add in the first step.
You can find your Realtime Database URL in the Realtime Database section of the Firebase console. Depending on the location of the database, the database URL will be in one of the following forms: https:// DATABASE_NAME . firebaseio.com (for databases in us-central1 )
Firebase is a Backend-as-a-Service (Baas). It provides developers with a variety of tools and services to help them develop quality apps, grow their user base, and earn profit. It is built on Google's infrastructure. Firebase is categorized as a NoSQL database program, which stores data in JSON-like documents.
For anyone googling that. You should use "admin" instead of "firebase".
Add:
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
in your requires at the start of the function js file, and ensure you use admin
in place of firebase
when initializing a connection.
For example:
Use:
admin.firestore().collection()
Instead of:
firebase.firestore().collection()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With