I have this snippet of code from my recent project, I am wondering why this returns false when I provide the correct input. I have put console logs everywhere and checked everything. I tried using global varibles, temp varables, all of that and nothing has worked so far.
var directoryPath = path.join(__dirname, 'images');
var result = false;
fs.readdir(directoryPath, function (err, files) {
var local = false;
//handling error
if (err) {
return console.log('Unable to scan directory: ' + err);
}
//listing all files using forEach
files.forEach(function (file) {
// Do whatever you want to do with the file
if(file == password) {
result = true;
}
});
});
return result