Created
February 13, 2014 20:54
-
-
Save kkemple/8983625 to your computer and use it in GitHub Desktop.
Function for walking over files in node are requiring them. Great for loading groups of objects such as routes, models, etc.
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 walk = function(path) { | |
fs.readdirSync(path).forEach(function(file) { | |
var newPath = path + '/' + file; | |
var stat = fs.statSync(newPath); | |
if (stat.isFile()) { | |
if (/(.*)\.(js$|coffee$)/.test(file)) { | |
require(newPath); | |
} | |
} else if (stat.isDirectory()) { | |
walk(newPath); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment