a.require

Require Node.js System

a.require for Node.js

Require manager for Node.js. Can execute same function as system require and some else

Install with npm

npm install a.require 

Configurate at first

var _require = require('a.require');
_require.init({root: __dirname});

Try it

Load Node.js module

var fs = _require('fs')

Load javascript file from root location

var simple = _require('./simple')

For example you has some file structure like this

application$ /private/tmp
├── app
│   ├── helpers
│   ├── modules
│   │   ├── core
│   │   │   └── models
│   │   │       └── settings.js
│   │   └── frontend
│   │       ├── controllers
│   │       │   └── index.js
│   │       ├── dao
│   │       │   └── posts.js
│   │       ├── models
│   │       │   └── posts.js
│   │       └── modules
│   │           ├── admin
│   │           │   ├── controllers
│   │           │   │   └── index.js
│   │           │   └── models
│   │           │       └── profile.js
│   │           └── auth
│   │               └── controllers
│   │                   └── users.js
│   └── utils
│       └── request.js
└── config
    └── app.yaml
 

Get index.js controller from frontend

var indexFrontend = _require("controller:app.frontend:index")

Get post.js model from frontend

var postModelFrontend = _require("model:app.frontend:posts")

Get posts.js dao from frontend

_require.init({names: {'dao': 'dao'}});
var postsDAOFrontend = _require("dao:app.frontend:posts")

Get index.js controller from frontend/admin

var indexAuthFrontend = _require("controller:app.frontend.auth:index")

Get request from utils

var request = _require("app:./utils/request")
var request = _require("./app/utils/request")

Get full path to file

var fullname = _require.path("config:app.yaml");

May be freely distributed under the MIT license

See LICENSE file

Copyright (c) 2013 - Sumskoy Andrew andy@away.name