Reputation: 839
I need help to show my data from my Firebase database as JSON to browser console log. I want load only Product
into browser console. I found a code for pushing data from this link. Can anyone help me figure out the function please?
var firebase = require('firebase');
//var admin = require('firebase-admin');
firebase.initializeApp({
apiKey: "...",
authDomain: "xxx.firebaseapp.com",
databaseURL: "https://xxx.firebaseio.com",
projectId: "xxx",
storageBucket: "xxx.appspot.com",
messagingSenderId: "xxx"
})
var ref = firebase.database().ref('Product');
//it's child directory
var messageRef = ref.child('/');
/*messageRef.push
({
prdName: 'node1',
prdCategory: 'node1',
prdSup: 'node1',
prdDescription: 'node1',
prdImage: 'test1.jpg',
prdUrl: 'https://firebasestorage.googleapis.com/v0/b/ng-product.appspot.com/o/Uploads%2Ftest1.jpg?alt=media&token=f105332a-02c8-46ca-a639-745eda0e118c'
})*/
console.log('Product');
Upvotes: 0
Views: 1549
Reputation: 598708
To get data from Firebase, you attach a listener. To then print it to the browser console, you call console.log()
in the callback:
var ref = firebase.database().ref('Product');
ref.once('value', function(snapshot) {
console.log(snapshot.val());
});
I highly recommend that you send some time reading the Firebase Database documentation, and take the corresponding codelab. A few hours spent in those will save many more hours down the line.
Upvotes: 1