nequire 
Requires files by namespaces.
Getting Started
Install the module with: npm install nequire
var nequire = require('nequire');
nequire.configure({
'helper': __dirname + '/helper'
});
nequire('helper', 'math/pi');
Documentation
Configuration
To use nequire
you must call the configure
method which expect a map of namespaces.
map
- Type:
Object
- Default: An empty
Object
The map contains the namespaces which will be made available. A key of the object is a namespace and the value is the associated path where the modules are located.
Usage examples
This is a simple webserver example which use nequire
.
index.js
var nequire = require('nequire'),
http = require('http');
nequire.configure({
'model': __dirname + '/models',
'route': __dirname + '/routes'
});
nequire.globalize();
var users = nequire('route', 'user');
var status404 = nequire('route', 'status-404');
var server = http.createServer(function (req, res) {
if (req.url.indexOf('/users') === 0) {
users(req, res);
} else {
status404(req, res);
}
});
server.listen(3000);
user.js
var User = nequire('model', 'user');
module.exports = function (req, res) {
User.find(function (err, users) {
res.setHeader('Content-Type', 'application/json');
if (err) {
res.end(err);
} else {
res.end(JSON.stringify(users));
}
});
};
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
License
Copyright (c) 2014 Florian Goße. Licensed under the MIT license.