I am using glob to generate an array of filepaths. I can push those paths to a new array and log them from within the glob function; however, when I attempt to access the array outside the scope of the function, the array returns empty. Am I misunderstanding how to use glob? What might be the problem?
I've also tried returning the array and it is still empty. Additionally, I can't use ajax for this program.
Thanks!
var fs = require("fs");
var glob = require("glob");
let scssFiles = [];
glob("css/**/**/*.scss", "matchBase:true", function(er, files) {
let file = '';
for (let i = 0; i < files.length; i++) {
file = files[i];
scssFiles.push(file);
}
console.log(scssFiles); // this works
});
console.log(scssFiles); // returns empty array