Created
April 1, 2018 06:14
-
-
Save aghontpi/cf7ec46a88af552947a9e29b7e3f8d49 to your computer and use it in GitHub Desktop.
learnyounode make it modular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var path = require('path') | |
module.exports = function(dir,extension,cbf){ | |
fs.readdir(dir,function(err,files){ | |
if(err){ | |
cbf(err,null); | |
} | |
else{ | |
cbf(null,files.filter(function(val){ | |
if(path.extname(val)=='.'+extension){ | |
return val; | |
} | |
})); | |
}}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lib = require('./extmodule.js'); | |
var dir = process.argv[2]; | |
var ext = process.argv[3]; | |
lib(dir,ext,function(err,files){ | |
if(err) | |
console.log(err); | |
else{ | |
files.forEach(function(val){ | |
console.log(val); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment