I'm writing a program that should filter and print the files of the given directory from the command line based on the file type.
mymodule.js :
var fs = require('fs');
var result=[];
exports.name = function() {
fs.readdir(process.argv[2], function (err, list) {
for(var file in list){
if(list[file].indexOf('.'+process.argv[3]) !== -1){
result.push(list[file]);
}
}
});
};
And in my actual file index.js:
var mymodule = require('./mymodule')
console.log(mymodule.name());
When the run the command
> node index.js SmashingNodeJS js //In SmashingNodeJS folder print all the .js files
The console.log is printing undefined, please let me know what I am doing wrong here and how to return/bind the content to exports.
name()method doesn'treturnanything, so what do you expect?mymodule.name(console.log)).