node-importer
v1.0.2
Published
Helps you to import (require) all sources in a given directory.
Downloads
7
Readme
importer
A node.js library that helps you to import (require) all sources in a given directory.
npm install --save node-importer
importer (options, handler)
Synchronously imports all sources in a given directory and calls handler.
options
(object || string): Import options. (or module directory path)handler
(function): is called when import each module.
Option | Description | Default ------- | --------------------------------------- | --------- path | Directory to import sources | - recursive | Boolean value indicating recursive mode | false
- Example usage:
var importer = require('node-importer');
importer('modules/', function(module, name) {
// foo.js : Hello world!
console.log(name + '.js : ' + module.hello());
});
importer.async (options, handler)
Asynchronously imports all sources in a given directory and calls handler.
importer.express (expressApp, options)
Use all modules in a directory as a express route.
NOTE: you need to export express.Router object in module. module.exports = router;
options
(object || string): Import options. (or module directory path)handler
(function): is called when import each module.
Option | Description | Default ------- | --------------------------------------- | --------- routePath | The path to connect routes. | / (root)
- Example usage:
importer.express(app, 'routes/');