Skip to content

Instantly share code, notes, and snippets.

@stephanielingwood
Created October 29, 2014 00:44
Show Gist options
  • Save stephanielingwood/bd01d088053f57dd05b0 to your computer and use it in GitHub Desktop.
Save stephanielingwood/bd01d088053f57dd05b0 to your computer and use it in GitHub Desktop.
Modules
var myModule = require("./formodular");
myModule(process.argv[2], process.argv[3], function(err, data) {
if (err) {
throw err;
}
for (i = 0; i < data.length; i++) {
console.log(data[i]);
}
});
var fs = require('fs');
var path = require('path');
//files is an array of filename strings
module.exports = function(dir, ext, callback) {
fs.readdir(dir, function(err, files) {
var list = [];
if (err) {
return callback(err);
}
for (i = 0; i < files.length; i++) {
var fileExt = path.extname(files[i]);
if (fileExt === ("." + ext)) {
// console.log(files[i])
list.push(files[i]);
// console.log(list[i])
}
}
callback(null, list);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment