Nodejs application with new Firebase does not retrieve database items

I am new to nodejs, but I already have a working js client program in Firebase version 3.0.2. Turns out I need a server to do some simple things that are not possible in the js client.

When I try this basic thing in nodejs, nothing happens - the data in the database is never retrieved, and the node server program continues to work without errors. The server program (server.js) is as follows:

var firebase = require("firebase"); var myApp =firebase.initializeApp({ serviceAccount: "xxx/xxx.json", databaseURL: "https://xxx.firebaseio.com" }); firebase.database().ref().on('value', function(snapshot) { console.log("urls value changed"); // NEVER GETS HERE console.log(snapshot.val()); }); 

Data is loaded into the database, and this is trying to look at the root. When I add items to the database through the console, nothing happens anyway. More specific ref () values ​​are not affected.

I am using node version v4.4.4. The program is invoked on the command line (on MBP / OSX) with "node server.js".

I spent hours trying to figure out what I was doing wrong - probably something stupid! Thank you for your help.

+7
firebase firebase-database
source share
1 answer

Fixed!

  • Added debugging, which is necessary:

    firebase.database.enableLogging(true)

  • I saw that there was an invalid token, and it was again disconnected / reconnected to try again. The lines in the log are similar:

    p: 0: from server: {"r": 2, "b": {"s": "invalid_token", "d": "Access denied." }}

    (NOTE: without registration, it was completely silent!).

  • It turned out that the service account is incorrect! You must first approve the terms of service! To do this, go to https://console.cloud.google.com/

  • Created a new service account and connected it - and finally it works!

+8
source share

All Articles