I have a problem in which i'm using a file to hold a list of modules and requiring this list in one call in my nodejs server. I want to use the modules in the list in a specific way.
modules.js -
Mods = {
mymodule: require('./mymodule.js')
}
exports.f = function() {
return Mods;
}
index.js -
f = require('./modules.js').f;
f().mymodule.echo("Hello World");
so instead of how i'm using f() now i want to put the name of the module i'm calling directly into the function so I can do things like this:
f = require('./modules.js').f;
f('mymodule').echo("Hello World");
I've tried a number of different experiments but can't get it to work, is it possible to do this in javascript?