I'm unable to get the data from database while running query inside the loop in node.js
when I run console.log(data) inside query then it's showing the data like code blew
app.post("/wtrecord/get/getall",authcheck,(req,res)=>{
let data = []
let token = req.body.token
con.query("SELECT date,SUM(hour_spend) FROM wtrecord WHERE user_token=? GROUP BY date",[token],(err,dates)=>{
if(err) throw err
if(dates){
async.ForEach
for(let i=0;i<dates.length;i++){
console.log(dates[i].date)
con.query("SELECT date,SUM(hour_spend) as totalhour,wtcategory.category_name FROM wtrecord INNER JOIN wtcategory ON wtrecord.category_uid=wtcategory.uid WHERE wtrecord.user_token=? AND wtrecord.date=? GROUP BY category_uid",[token,dates[i].date],(err,result)=>{
data[dates[i].date] = result
console.log(data)
})
}
console.log("This is the real data")
console.log(data)
}else{
}
})
res.send(data)
})
but whenever I run the console.log(data) outside the second query it's didn't show anything even data variable is not appending.
Thanks