var app = express();
var cloud = firebase.firestore();
app.get('/getMyDatas', function (req, res) {
let tList = [];
let tJson = {};
cloud.collection('contents/').orderBy('date').get().then((contents) => {
contents.docs.forEach(cont=> {
cloud.collection('userprofile/').where('userId', '==', cont.data().userId).get().then((users) => {
users.docs.forEach(user => {
tJson = {description:cont.data().description, name:user.data().name};
tList.push(tJson);
tJson = {};
console.log("LIST IS FILLED SUCCESFULLY : " + JSON.stringify(tList));
});
});
});
console.log(" ??HERE THE LIST IS EMPTY : " + JSON.stringify(tList));
res.json(tList);
});
});
This code can create the list i want. But i can't use it on the line that says "res.json(tList)".
I can use on the line that says "console.log('My List : ' + JSON.stringify(tList));" (it shows my list correctly.)
res.json(tList) return "[]" empty list. How can i use this on this line?