Sunday, 2 December 2018

not returning data to client-side

i'm putting the data (from the promise) into res. At best, I am getting nothing back but 5 headers. Tinkering the code in sending it back client-side resulted into 'can't set headers after they're sent' (using res.send(data)) or unexpected U JSON when I used JSON.parse. For the latter, it means my data is undefined meaning I'm likely not capturing the data from the promise. What am I missing here?​​ getUsers(req, res) { var usersRef = db.collection('users'); usersRef.get() .then(snapshot => { snapshot.forEach(doc => { console.log(doc.id, '=>', doc.data().name); let data = {uid: doc.id, name: doc.data().name}; return data; }); }) .then( data => { res.json(data); }) .catch(err => { console.log('Error getting documents', err); process.exit(); }); ​

Submitted December 02, 2018 at 09:11AM by kekcoke

No comments:

Post a Comment