I have a frustrating issue happening right now. I'm trying to make a function that gets the files in a directory, but it just wont return the items.
function get_items(){
fs.readdir(entire_path, function(err, items){
console.log(items.join("\n"))
return items.join("\n");
});
}
console.log(get_items());
As you can see in this code, it console.logs the items, then returns the items, and then at the bottom it console.logs the output of the function. The console.log in the function works, but the second one does not. Why is this happening? This only happens in a function as well.
EDIT 1
Please don't mark as duplicate, I don't want to do
get_items(function(){
//do stuff
});
I want to be able to just do get_items();
EDIT 2
I used readdirSync instead.