gouf
2/3/2015 - 1:59 PM

MAKE IT MODULAR

MAKE IT MODULAR

Learn You The Node.js For Much Win! An intro to Node.js via a set of self-guided workshops.

var filter = require('./filter')

var directory_path   = process.argv[2],
    filterStr = process.argv[3];

filter(directory_path, filterStr, function (err, data) {
    if (err) { return console.error('Error : ', err); }

    data.map(function (list) {
        console.log(list);
    });
});
module.exports = function (directory_path, filterStr, callback) {
  var fs = require('fs');
  fs.readdir(directory_path, function (err, list) {
    if (err) { return callback(err); }

    var list_result = list.toString().split(',').filter(function (m) {
      return m.match('.' + filterStr);
    });

    return callback(null, list_result);
  });
}