in a module containing two files in ./modx: modx.js and helper.js:
./modx/package.json:
{ "name" : "module x",
"main" : "./modx.js" }
./modx/helper.js:
function subFunc() { }
./modx/modx.js:
exports.mainFunc = function() {
var x = subFunc();
}
how do I make subFunc() in helper.js visible to modx.js when both are in the modx module?
Inside ./modx/helper.js
var subFunc = function subFunc() {}
exports.subFunc = subFunc;
Inside .modx/modx.js
var helper = require('./helper.js');
exports.mainFunc() {
var x = helper.subFunc();
}
The result here is that the subFunc function in helper.js is externally available and the mainFunc in modx.js is externally available.
The only object in script A visible from script B is module.exports. Adding objects/functions to module.exports (just like you did it with mainFunc) makes them visible from the outside. There is no other way.