Skip to content

Instantly share code, notes, and snippets.

@tanyagupta
Created December 5, 2015 22:15
Show Gist options
  • Save tanyagupta/98f045fb046aaeeef777 to your computer and use it in GitHub Desktop.
Save tanyagupta/98f045fb046aaeeef777 to your computer and use it in GitHub Desktop.
MAKE IT MODULAR (Exercise 6 of 13)
var mod = require('./module1');
mod(process.argv[2], process.argv[3], function (err, listf) {
if (err) {
console.log('Error!')
} else {
for (var i = 0; i < listf.length; i++) {
console.log(listf[i]);
}
}
});
var fs = require('fs');
var ph= require('path');
module.exports = function (path, ext, callbk) {
var extn = "." + ext;
fs.readdir(path, function (err, files) {
if (err)
return callbk(err);
else {
var listf = []; /
for (var i = 0; i < files.length; i++) {
if (ph.extname(files[i]) === extn) {
listf.push(files[i]);
}
}
callbk(null, listf);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment