Skip to content

Instantly share code, notes, and snippets.

@oliverswitzer
Created February 24, 2014 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oliverswitzer/9194514 to your computer and use it in GitHub Desktop.
Save oliverswitzer/9194514 to your computer and use it in GitHub Desktop.
Node.js Module Example!
// 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