I could use help returning an object created from reading files in a folder and saving their hash values and name to an object.
checkHashedFolder(dir1, dir2) {
const directory1 = dir1.replace(/@@@@@/g, '/');
const directory2 = dir2.replace(/@@@@@/g, '/');
var hashedFolder = [];
fs.readdir(directory1, function(err, files) {
if (err) {
console.error("Could not list the directory.", err);
}
files.forEach(function(file, index) {
let newPath = path.join(directory1, file);
return fs.readFile(`${newPath}`, 'utf8', function(err,data) {
if (err) {
return console.log(err);
}
hashedFolder.push({
name: file,
hash: data
});
return hashedFolder;
});
});
return hashedFolder;
});
}
I know the object is being built how I would like it to because i've logged it. I just don't know how to return the object that is being created. Thanks.