Skip to content

Instantly share code, notes, and snippets.

@amatiasq
Created July 17, 2013 16:21
Show Gist options
  • Save amatiasq/6022122 to your computer and use it in GitHub Desktop.
Save amatiasq/6022122 to your computer and use it in GitHub Desktop.
A file to load every file found on the same folder or subfolders.
'use strict';
var fs = require("fs");
function scan(dir) {
var files = [];
fs.readdirSync(dir).forEach(function(file) {
var path = dir + '/' + file;
var stat = fs.statSync(path);
if (stat.isDirectory())
return files.concat(scan(path));
if (stat.isFile())
return files.push(path);
});
return files;
}
scan(__dirname).filter(function(file) {
return file !== __filename;
}).map(require);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment