I have several questions that I’m stuck on. First here’s the code for the Module I have written so far:
var fs = require("fs");
var path = require("path");
module.exports = function (input, filter, cback) {
fs.readdir(input, function doneReading(err, list) {
if (err) return callback(err)
for (var i = 0; i < list.length; i++) {
var extension = list[i].split(".").pop();
if (extension == filter && list[i].split(".").length != 1) {
console.log(list[i]);
}
}
});
};
Here’s the code for the Main file that calls the Module:
var program = require("./program");
program(process.argv[2], process.argv[3], function() {});
First, I know it’s a placeholder and isn’t right since there has to be more to it but in the Main file I don’t understand what I’m supposed to do with the passed in callback so I did a placeholder since my code passes all the tests except for the test I have a question on below. So first thing is how does a passed in callback to a module work?
Second question, the test results are these:
Your submission results compared to the expected:
ACTUAL EXPECTED
────────────────────────────────────────────────────────────────────────────────
"CHANGELOG.md" == "CHANGELOG.md"
"LICENCE.md" == "LICENCE.md"
"README.md" == "README.md"
"" == ""
────────────────────────────────────────────────────────────────────────────────
✓
Submission results match expected
✓
Additional module file exports a single function
✓
Additional module file exports a function that takes 3 arguments
✗
Your additional module file [program.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)
# FAIL Your solution to MAKE IT MODULAR didn't pass. Try again!
If you see the code above I did include an err check inside the readdir callback but for some reason it doesn’t get counted correctly and I don’t know why.