0

Help me please.

I want require all files from directory ? How best to do it?

I read about require_paths but it does not perform those functions.

4

1 回答 1

0

您可以浏览一个目录并要求每个目录:

var mods = {};
var files = fs.readdirSync('your_directory').filter(function(x) { return x.substr(-3) == ".js"; });
for(var i = 0; i != files.length;++i) {
    mods[files[i]] = require(path.join('your_directory',files[i]));
}
于 2013-10-21T18:18:53.953 回答