easy-require

1.0.1 • Public • Published

easy-require

Wrapper around require that supports paths from the application root and requiring directories as namespaces

Code Climate Build Status Dependency Status devDependency Status

This module was mostly created to be used with large applications where you can forget where specific items are relative to where you are but you're conventions make it easy to get to them from the applications root

The ability to require an entire directory as a namespace came out of my laziness.

Usage

npm install --save easy-require

var app = {}; app.require = require('easy-require');

// require a module local to the root directory // just start it with ~/ to denote that it's relative to the app root app.require('~/modules/cart/models/tax');

// require a directory and its children as a namespace // just pass in true as the second parameter to recursively include a directory to a namespace app.require('./controllers', true); // the optional true tells it to treat the require as a namespace

// requiring anything else app.require('normal path you would include'); // everything else is just a normal require

Performance

Easy-require is extremely performant adding little overhead on the initial require It also performs significantly better than regular require when requiring the same modules in an application

Requiring a directory into a namespace is also performance oriented but can slow down with very large directory structures if you have a need for a namespace that will end up using more than 50 modules please load them at startup, additional requires after this will use a cache so you don't have the performance hit at runtime

To view cached reference performance results please look in the perf directory there is a linux, windows, and mac result available.

While the results were consistent across all of my machines this module hasn't been battle tested yet so please run tests on your own environment and codebase and open an issue if you find any discrepencies

Package Sidebar

Install

npm i easy-require

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • thotjs