Firebase Node.js

94 views
Skip to first unread message

Ankur Mahesh

unread,
May 23, 2016, 10:01:24 PM5/23/16
to Firebase Google Group
I am using Firebase (3.x) in a node.js app.  I am trying to get data from my firebase database. I initialized the SDK as the docs indicated, and my security rules are public.  I have five "users" under MYFIREBASEURL.firebaseio.com/users. They are visible on the firebase developer console.

var db = Firebase.database();
var usersRef = db.ref("users");

var numbers = [];
usersRef.on('child_added', function(snapshot) {
  numbers.push( snapshot.val() );
  console.log( 'Added number ' + snapshot.val() );
});

In the above code snippet, no data is added to the numbers array, even though I have five "users."

However, when I change the code slightly to the following: 

var db = Firebase.database();
var usersRef = db.ref("users");
usersRef.push("1234567");

var numbers = [];
usersRef.on('child_added', function(snapshot) {
  numbers.push( snapshot.val() );
  console.log( 'Added number ' + snapshot.val() );
});
the event listener finds "1234567," but it does not find any of the other five pre-existing users.  1234567 (along with the five other users) are visible on my firebase database in the developer console.  What might be the problem?  Thanks for your help!

Jacob Wenger

unread,
May 23, 2016, 10:27:27 PM5/23/16
to fireba...@googlegroups.com
​Hey Ankur,

Where in your code are you initializing the SDK with a service account? Can you share a full, minimal repro (not including your service account) and paste it here?

Cheers,
Jacob​

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/bcda65cf-52f5-426f-a682-71dae949d448%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ankur Mahesh

unread,
May 24, 2016, 10:23:22 AM5/24/16
to Firebase Google Group
Hi,

I am initializing the SDK at the beginning of the file.
var Firebase = require("firebase");
Firebase.initializeApp({
  serviceAccount: "(the path to the JSON file I downloaded)",
  databaseURL: "(mydatabaseurl)"
});

var db = Firebase.database();
var ref = db.ref();
var usersRef = ref.child("users");
var testRef = ref.child("test");

usersRef.push("456");
var numbers = [];
usersRef.on('child_added', function(snapshot) {
  numbers.push( snapshot.val() );
  console.log( 'Added number ' + snapshot.val() );
});
usersRef.push("123");

testRef.on('value', function(snapshot) {
  console.log('Added test ' + snapshot.val());
});
Even though there are already five users, the event listener only finds "123" and "456."  "123" and "456" show up in my developer console, along with the five other preexisting users.  testRef finds nothing, even though it should find "789".  (I can see test: "789" in the developer console.)

When I created a new service account, I encountered a "server error" (screenshot attached).  However, when I refreshed the page, the service account I created showed up in my list of service accounts. I downloaded a JSON file that had the credentials by clicking the three dots (settings) --> "create key."  Could there still be something wrong with the service account?

Thanks!
Screen Shot 2016-05-23 at 8.14.35 PM.png

Jacob Wenger

unread,
May 24, 2016, 12:02:55 PM5/24/16
to fireba...@googlegroups.com
Yes, there is a known issue with service account creation if you have not yet accepted the Google Cloud Terms of Service. Sorry for the troubles this has caused you. You can accept them by going here. Once you accept them, try re-creating a new service account and make sure you don't get an error. Then use the credentials JSON file from that service account and let me know if things work.

​If that still doesn't work, try reading through this other thread and trying to suggestions towards the end of it.​ We are working diligently to resolve the Terms of Service bug but it is not an easy one for us to resolve.

​Cheers,​
​Jacob​

Ankur Mahesh

unread,
May 26, 2016, 2:56:30 PM5/26/16
to Firebase Google Group
Accepting the Google Cloud Terms of Service appears to have solved the problem!  Sorry if this post was redundant with the other thread! My problem was, indeed, with service account creation.
Reply all
Reply to author
Forward
0 new messages