1.0.2 • Published 9 years ago

node-importer v1.0.2

Weekly downloads
8
License
MIT
Repository
github
Last release
9 years ago

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.
OptionDescriptionDefault
pathDirectory to import sources-
recursiveBoolean value indicating recursive modefalse
  • 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.
OptionDescriptionDefault
routePathThe path to connect routes./ (root)
  • Example usage:
importer.express(app, 'routes/');

License: MIT

Author: Hyojun Kim