I am trying to access returned values from an asynchronous function but I keep getting undefined. I have tried a ton of suggestions from SO but cant seem to get what I need. I want to be able to access the values in the logs array.
const jsonPath = '';
let logs = [];
function getLogs(folderPath, callback){
fs.readdir(folderPath, (err, files) => {
if(!err){
files.forEach(file => {
let response = fs.readFileSync(folderPath + '/' + file, 'utf8')
logs.push(JSON.parse(response).changelog);
})
}
else{
console.log('Error: ' + err);
}
callback(logs);
})
}
getChangelogs(jsonPath, function(result){
return logs; //I want to be able to access this logs array
})