Created
February 24, 2014 18:54
-
-
Save oliverswitzer/9194514 to your computer and use it in GitHub Desktop.
Node.js Module Example!
This file contains hidden or 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
// dirListModule.js | |
var fs = require('fs'); //require node filesystem module | |
var path = require('path'); //require node path module (a couple of tools for reading path names) | |
module.exports = function filterDirFiles(pathSupplied, extFilter, callback) { | |
function extension(element) { | |
var extName = path.extname(element); | |
return extName === '.' + extFilter; | |
}; | |
fs.readdir(pathSupplied, function (err, list) { | |
if (err) { | |
return callback(err); | |
}; | |
return callback(null, list.filter(extension)) | |
}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment