Small solution for easy nodejs libraries connection
npm install libe
Small solution for easy nodejs libraries connection
bash
npm install libe --save
`
Getting Started
Put your files into the directory /lib and they will be available everywhere:`js
var through = lib('through');
var duplexer = lib('duplexer');
var myModule = lib('myModule');
`
Example
index.js:
`js
require('libe');// include file
my.js from /lib
var my = lib('my');my.func();
`lib/my.js:
`js
// include file great.js from /lib
var great = lib('great');exports.func = great.func;
`lib/great.js:
`js
exports.func = function () {
console.log("Aloha!");
};
`
What else?
Initialize your modules! So simple. Just add exports.init method to your library. Like this:
lib/my.js:
`js
var great = lib('great');exports.init = function (callback) {
console.log('Module
my.js initialized!');
callback();
}
exports.func = great.func;
`lib/great.js:
`js
exports.init = function (callback) {
after(['my'], function () {
console.log('Module great.js initialized after my.js!');
callback();
});
}
exports.func = function () {
console.log("Aloha!");
};`Then add
libe.init to your main file: index.js:
`js
var libe = require('libe');
var my = lib('my');libe.init(function () {
my.func();
});
`
That's all! Change directory path
`js
var libe = require('libe');libe.setPath('/srv/myProject2/libs');
`or:
`js
var libe = require('libe');libe.init('/srv/myProject2/libs', function () {
// ...
});
``Author is Oleksiy Chechel