glob-require

0.0.2 • Public • Published

glob-require

Use glob to find and call require on all matching files in a directory tree.

Installation

npm install --save glob-require

Usage

  1. Install using npm: npm install glob-require
  2. Include it in your source:
const globRequire = require('glob-require');
 
// simple case, pass in a subdirectory to include to
// search for and require all .js files.
globRequire(SUBDIR_TO_INCLUDE, function(err, includes) {
  // includes is an array of included files.
  // each include contains two fields:
  // * path - full path to included file
  // * exports - the return value of `require`
  processIncludes(includes);
});
const globRequire = require('glob-require');
 
// advanced case, pass a 'glob' pattern and configuration object.
// See https://github.com/isaacs/node-glob#options for a list of options.
globRequire('**/*.js', {
  cwd: SUBDIR_TO_INCLUDE
}, function(err, includes) {
  // includes is an array of included files.
  // each include contains two fields:
  // * path - full path to included file
  // * exports - the return value of `require`
  processIncludes(includes);
});

Run the tests

npm test

Get involved:

If you find a bugs or see any features you wish to add, file an issue or submit a pull request!

Repo information:

https://github.com/shane-tomlinson/glob-require

Author:

License:

This software is available under version 2.0 of the MPL:

https://www.mozilla.org/MPL/

Package Sidebar

Install

npm i glob-require

Weekly Downloads

4

Version

0.0.2

License

MPL-2.0

Last publish

Collaborators

  • stomlinson