how can i require a module globally so i can use it in different modules without having to require it again? or do i just have to do that everytime? is there any best practice for this?
heres an example of what i am talking about. lets say i have an index.js like this:
var a = require('a.js'),
utils = require('utils.js');
var str = 'hello this is a test';
str = a.change(str);
utils.return(str);
a.js
var utils = require('utils.js');
exports.change = function(str) {
str = str.replace('test', 'example');
utils.return('i changed test to example!');
return str;
}
utils.js
exports.return = function (msg) {
console.log(msg);
}
you see i have to require('utils.js') twice, but i would rather require it once in the index.js and have it available in the index.js and a.js as utils. is there any good way to accomplish that?