fs.readdir callback function code example
Example: fs.readdir callback function
const Promise = require('bluebird');
const fs = Promise.promisifyAll(require('fs'));
var arr = [];
fs.readdirAsync(folder).then( files => {
files.forEach(file => {
fs.stat(folder + '/' + file, (err, stats) => {
if(!stats.isDirectory()) {
arr.push(file);
return;
}
});
});
})
.then( () => {
console.log(arr);
});