Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to get list from Firebase database in node.js

Tags:

node.js

I'm learning Firebase and Node.js. I want get my chat list from Firebase but not able to read data.

My code:

var firebase = require("firebase");
var config = {
    apiKey: '<API_key>',
    authDomain: '<project_key>',
    databaseURL: "https://'<database>'/"
};

firebase.initializeApp(config);

// Get a reference to the database service
var db = firebase.database();

var ref = db.ref('Module1/Talk');
ref.once("value", function(snapshot) {
  console.log(snapshot);
}, function (errorObject) {
  console.log("The read failed: " + errorObject.code);
});

I m getting this in response:

W {
  A: 
   P {
     k: wf { Ka: [Function: fc], ba: Jf {} },
     aa: null,
     wb: ge { ld: [Object], ac: [Object] },
     Bb: '' },
  V: 
   U {
     u: 
      Ue {
        app: [Object],
        L: [Object],
        Ua: [Object],
        Sc: null,
        ca: [Object],
        td: 1,
        Qa: [Object],
        va: [Object],
        og: [Object],
        jc: [Object],
        de: [Object],
        md: [Object],
        ia: [Object],
        Xa: [Object],
        cd: 0,
        ee: null,
        K: [Object] },
     path: L { o: [Object], Y: 0 },
     m: 
      be {
        xa: false,
        ka: false,
        Ib: false,
        na: false,
        Pb: false,
        oa: 0,
        kb: '',
        bc: null,
        xb: '',
        Zb: null,
        vb: '',
        g: Xd {} },
     Kc: false,
     then: undefined,
     catch: undefined },
  g: Xd {} }
like image 580
Aman Jain Avatar asked Jun 30 '26 11:06

Aman Jain


1 Answers

As per Docs, You need to call .val() to get the value

Calling val() / getValue() on a snapshot returns the JavaScript object representation of the data.

var ref = db.ref('Module1/Talk');
ref.once("value", function(snapshot) {
  console.log(snapshot.val());  //call the .val() here
}, function (errorObject) {
 console.log("The read failed: " + errorObject.code);
});
like image 151
Sridhar Avatar answered Jul 02 '26 07:07

Sridhar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!