I'd like to dynamically load and call Javascript functions with a JSON file. The idea is to build a plugin framework that would others to add functionality by simply writing a function and updating the JSON file.
For example, with the following JSON:
{
"plugins" : {
"random" : {
"name" : "Random number generator",
"hook" : "random"
}
}
}
... and the following plugin: random.js
module.exports.run = function() {
return Math.round(Math.random() * 100);
}
I'd like to be able to parse the JSON file and call the run function of any plugin. How can I load and call the run function on random?