Skip to content

Instantly share code, notes, and snippets.

@ds0nt
Created February 14, 2015 01:59
Show Gist options
  • Save ds0nt/554c38b7ab0aa47e1a69 to your computer and use it in GitHub Desktop.
Save ds0nt/554c38b7ab0aa47e1a69 to your computer and use it in GitHub Desktop.
recursive load files from directory
var path = require('path');
var nodedir = require('node-dir');
module.exports = function (root, ext, done) {
var data = {};
var onFile = function(err, content, filename, next) {
if (err) throw err;
data[filename.replace(root, '').replace(ext, '')] = content;
next();
}
var onComplete = function(err, files) {
if (err) throw err;
done(data);
}
nodedir.readFiles(root, { match: ext }, onFile, onComplete);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment