dir-require
Require a directory of js modules.
Install
$ npm install --save dir-require
Examples
require other modules in index.js when the file tree is like
.
├── index.js
├── testModule1.js
└── testModule2.js
your js code in index.js
const models = ; // 1st argument is absolute path /*You will getmodels = { 'testModule1': require('testModule1'), 'testModule2': require('testModule2'),} */
const models = ; /*You will getmodels = [require('testModule1'), require('testModule2')]; */
Usage
const moduleLoader = ; moduleLoader;moduleLoader;
dirpath
should be absolute path.
options.match
- String (only load this file)
- Array of String (only load files in array)
- Regx (load files match regx)
options.ignore
- String
- Array of String
- Regx
- if options.match is set options.ignore is no use.
License
MIT © liu946