lazy-modules-directory
v0.1.0
Published
lazy load modules from a directory
Downloads
1
Readme
about
lazy-modules-directory
is a simple module that scans a directory and creates pending getters for all modules contained (as .js files or as directories containing index.js), when the module name property is accessed the module is loaded and the property is replaced by the actual module
useful for when you might have cross dependency between modules (eg: database models) or if you want to dynamically load modules only when needed (eg: plugins)
installation
npm install --save lazy-modules-directory
by example
const modules = require('lazy-modules-directory')('module_directory')
modules.modulename // would load the given module if module_directory contains either modulename.js or modulename/index.js
API
lazy-modules (dirname, { camelCase, requireFn })
- dirname - (required) directory to scan for modules
- options
- camelCase - convert module names to camelCase (eg: given module_name.js the property exposed would be called moduleName)
- requireFn - an alternative callback for loading a module, eg: (dirname, name) => return [implemented module]
License: MIT