Created
February 14, 2015 01:59
-
-
Save ds0nt/554c38b7ab0aa47e1a69 to your computer and use it in GitHub Desktop.
recursive load files from directory
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 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