0

How do I output the value of a node? I tried

let item = firebase.database().ref('maps/').child('redzone');
console.log(item.toJSON());

and

let item = firebase.database().ref('maps/').child('redzone');
console.log(JSON.stringify(item.toJSON()));

but every time I just get the firebase URL, not the actual object. How do I read it?

1
  • Have you tried firebase.database().ref('maps').child('redzone');? Commented Sep 26, 2018 at 17:02

1 Answer 1

2

None of your code reads data fro the database yet. All it does is create a reference to a location in the database. To read data you have to use on() or once(). For example:

let ref = firebase.database().ref('maps/').child('redzone');
ref.once("value", function(snapshot) {
  console.log(snapshot.val())
})

This is all quite well covered in the Firebase documentation and codelab for web developers, so I recommend spending some time in those.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.