https://github.com/timnew/lazily-require
Require node.js files from folder lazily. Could be useful in application.
https://github.com/timnew/lazily-require
Last synced: 12 months ago
JSON representation
Require node.js files from folder lazily. Could be useful in application.
- Host: GitHub
- URL: https://github.com/timnew/lazily-require
- Owner: timnew
- License: mit
- Created: 2014-07-13T18:17:14.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-09-13T09:19:07.000Z (over 11 years ago)
- Last Synced: 2025-02-28T18:00:46.367Z (over 1 year ago)
- Language: CoffeeScript
- Homepage: https://github.com/timnew/lazily-require
- Size: 156 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
lazily-require [![NPM version][npm-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Dependency Status][depstat-image]][depstat-url]
================
> Require node.js files from specific path. The file name is mapped to property name.
> The requirement happened lazily, the module won't be required until it is accessed.
> Could be useful in application, requirements can be simplified by using in conjunction with [approot](https://github.com/timnew/approot)
## Install
Install using [npm][npm-url].
$ npm install lazily-require
## Usage
```javascript
var lazy = require('lazily-require');
var Models = lazy('./modules');
var User = Models.User; // equivalence to require('./modules/User')
var Credential = Models.admin.Credential; // equivalence to require('./modules/admin/Credential')
```
When used in conjunction of [approot](https://github.com/timnew/approot) to initialize the application environment.
```javascript
var lazy = require('lazily-require');
global.appRoot = require('approot')(__dirname).consolidate();
global.configuration = require(appRoot.config('configuration'));
global.Services = lazy appRoot.services();
global.Routes = lazy appRoot.routes();
global.Records = lazy appRoot.records();
global.Models = lazy appRoot.models();
global.Entities = lazy appRoot.entities();
// Reference as
var user = Models.User;
var user = new User();
var user2 = new Models.User();
app.get('/admin/login', Routers.admin.login.get);
```
## License
MIT
[![NPM downloads][npm-downloads]][npm-url]
[homepage]: https://github.com/timnew/lazily-require
[npm-url]: https://npmjs.org/package/lazily-require
[npm-image]: http://img.shields.io/npm/v/lazily-require.svg?style=flat
[npm-downloads]: http://img.shields.io/npm/dm/lazily-require.svg?style=flat
[ci-url]: https://drone.io/github.com/timnew/lazily-require/latest
[ci-image]: https://drone.io/github.com/timnew/lazily-require/status.png
[depstat-url]: https://gemnasium.com/timnew/lazily-require
[depstat-image]: http://img.shields.io/gemnasium/timnew/lazily-require.svg?style=flat