node package manager
Orgs are free. Discover, share, and reuse code in your team. Create a free org »



Auto-require all matching files within a directory recursively and return them as single object, representing the directory's structure.

npm Package Version MIT License Travis Build Status Code Climate GPA Code Climate Test Coverage

Dependencies Status devDependencies Status


var ReqMapper = require('requirements-mapper'),
    dataMapper = new ReqMapper('./data')),
    dataMap =;


Assuming that ./data is a directory containing multiple files using subfolders like this:

 ├─╸ other/
 │    ├─╸ bar.js
 │    └─╸ baz.json
 └─╸ foo.js

An object of which every node contains the required contents of the respective file will be returned by

    other: {
        bar: …
        baz: …
    foo: …


The constructor of RequirementsMapper accepts 3 parameters:

  • dir - directory to scan; defaults to process.cwd()
  • globPattern - globbing pattern for finding files; defaults to **/*.js?(on)
  • clearCache - clear the require cache for a node, before requiring it; defaults to true

See node-glob for more details on globbing options.


MIT Simon Lepel 2015