if (args[0] === "help") {
var help_array = [];
fs.readdir('./commands/', (err, files) => {
files.forEach((response) => {
var commandFile = require('./commands/' + response);
help_array.push(commandFile.getHelp());
console.log(help_array); // <----- array with elements
});
});
console.log(help_array); // <----------- empty array []
return;
}
Why is this happening? How i can solve this? It is related to async function?