-
-
Save stephanielingwood/bd01d088053f57dd05b0 to your computer and use it in GitHub Desktop.
Modules
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 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]); | |
} | |
}); |
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'); | |
//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