im writing a route to try and return 5 random files with a for loop.. I cant seem to get arr.push(file) to work sync. Any ideas?
router.get('/test', async (req, res) => {
let amountOfFiles = 5;
let arr = []
for( let i =0; i < amountOfFiles; i++){
let num = Math.floor(Math.random() * 100)
await gfs.files.findOne({filename: `${num.toString()}.mp3` }, async (err, file) => {
if(!file){
return res.json({
err: 'upload'
})
}
// console.log(file)
arr.push(file)
})
}
//console.log(gfs.files.find())
console.log(arr)
return res.json(arr)
})