var fs = require('fs');
var path = require('path');
module.exports = function(folderPath, ext, callback){
ext = '.' + ext;
fs.readdir(folderPath, 'utf8', function(err, files){
if (err){
callback(err, null);
}
else{
let outputFiles = [];
for (let i = 0; i < files.length; i++){
if (path.extname(files[i]) === ext){
outputFiles.push(files[i]);
}
}
callback(err, outputFiles);
}
});
};
In this line, fs.readdir(folderPath, 'utf8', function(err, files){...}, I add option of 'utf8' then learnyounode's feedback is FAIL Your solution to MAKE IT MODULAR didn't pass. Try again!
However, I erase the 'utf8' and change code to fs.readdir(folderPath, function(err, files){...} then I pass all test!
This is my program.js.
var extSearch = require('./extSearch.js');
var folderPath = process.argv[2];
var ext = process.argv[3];
extSearch(folderPath, ext, function(err, files){
if (err){
console.log(err);
}
else{
for (let i of files){
console.log(i);
}
}
});
This is my module that is extSearch.js.
In this line, fs.readdir(folderPath, 'utf8', function(err, files){...}, I add option of 'utf8' then learnyounode's feedback is FAIL Your solution to MAKE IT MODULAR didn't pass. Try again!
However, I erase the 'utf8' and change code to fs.readdir(folderPath, function(err, files){...} then I pass all test!
This is my program.js.