I cannot pass this excercise because it complaines about
✗ Your additional module file [readdir.js] does not appear to pass back
an error received from fs.readdir(). Use the following idiomatic Node.js
pattern inside your callback to fs.readdir(): if (err) return
callback(err)
When I manually try to execute the program to produce an error it reports it
philipp@debian-acer5750g ~/devel/js/fcc/lynode % node program.js adkjvbas
There was an error Error: ENOENT: no such file or directory, scandir 'adkjvbas'
Can someone help me to see what the problem is here?
//// file: program.js
const readdir = require("./readdir")
const args = [...process.argv].slice(2);
readdir(args[0], (err, data) => {
if (err) {
return console.log("There was an error " + err);
}
data.forEach((val) => console.log(val));
}, args[1]);
//// file: readdir.js
const fs = require("fs");
const path = require("path");
module.exports = (dirname, callback, ext) => {
fs.readdir(dirname, (err, data) => {
if (err) {
return callback(err);
}
let filteredDir = data.filter((val) => {
if (ext) {
return path.extname(val) === "." + ext;
} else {
return true;
}
})
callback(null, filteredDir);
})
}