Luca Mormile Luca Mormile - 5 months ago 47
Node.js Question

Firebase 3 - Can't retrieve data from database (Web)

I'm working on a webapp using

Firebase 3
(the latest version) for the first time but I'm having troubles with
retrieving data
on my page.

I've created a
NodeJS
test app from
Heroku
, then I'm trying to retrieve my data in JSON format (ref's path goes to my data array) saved in my Firebase
realtime database
.
I've followed the doc, but without results.

Here's my code:

<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"></script>
<script>

// Initialize Firebase
var config = {
apiKey: "*******",
authDomain: "*******",
databaseURL: "*******",
storageBucket: "*******",
};

firebase.initializeApp(config);
firebase.database().ref('my/path/to/data').on('value', function(snapshot) {
console.log('kk'); //no log in the console
});

</script>


There are no errors in the console, but no results too. It seems so simple to do but I can't figure out what I'm missing.

Answer

This has been working in my application:

firebase.database()
  .ref(`/database/path`)
  .once('value')
  .then((snapshot) => { console.log('hi') });