nodejs plugin like webpack require-context.
npm install node-plugin-require-context
!Downloads

> nodejs plugin like webpack require-context.
Inspiration from webpack's require.context,You can batch import files in NodeJs.
install
``npm`
npm install --save-dev node-plugin-require-context
Example
`js
const requireContext = require('node-plugin-require-context');
const context = requireContext('./', true, /\.js$/, __dirname);
context.keys().forEach(modulePath => {
/ get module /
context(modulePath);
});
`
requireContext ( directory, useSubdirectories, regExp, rootPath, fn )
- directory
> search dir, you can input like './' or '../' and so on, Required parameter.
- useSubdirectories
> true will search all child file; false only search current dir, Required parameter.
- regExp
> RegExp match; match the files you need,Required parameter.
- rootPath__dirname
> this is indispensable,The fixed value is , Required parameter.
- fn
> A callback function; when matching to the correct file will call it,Optional parameters
The context` function has 2 properties: resolve and keys.
- resolve is a function and when passed in the module relative path and returns absolute path.
- keys is a function that returns an array of all possible requests that the context module can handle.