Skip to content

Instantly share code, notes, and snippets.

@aghontpi
Created April 1, 2018 06:14
Show Gist options
  • Save aghontpi/cf7ec46a88af552947a9e29b7e3f8d49 to your computer and use it in GitHub Desktop.
Save aghontpi/cf7ec46a88af552947a9e29b7e3f8d49 to your computer and use it in GitHub Desktop.
learnyounode make it modular
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;
}
}));
}});
}
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