Let\'s say I have a file called app.js. Pretty simple:
var express = require(\'express\');
var app = express.createServer();
app.set(\'views\', __dirname + \
You need no new functions nor new modules. You simply need to execute the module you're calling if you don't want to use namespace.
module.exports = function() {
this.sum = function(a,b) { return a+b };
this.multiply = function(a,b) { return a*b };
//etc
}
or in any other .js like myController.js :
instead of
var tools = require('tools.js')
which force us to use a namespace and call tools like tools.sum(1,2);
we can simply call
require('tools.js')();
and then
sum(1,2);
in my case I have a file with controllers ctrls.js
module.exports = function() {
this.Categories = require('categories.js');
}
and I can use Categories
in every context as public class after require('ctrls.js')()