mercredi 20 mai 2015

Node.js external plugins pattern

I came across this code in the karma project.

Basically it allows anyone to define external plugins that would be loaded by karma.

when karma starts it runs this code:

modules = modules.concat(plugin.resolve(config.plugins));
var injector = new di.Injector(modules);

Which tells the plugin loader to look for any node_modules that match the names in config.plugins.

Then of course it assumes that the plugins have some interface and it connects them to karma events accordingly.

This seems like a very good implementation for allowing external plugins to be loaded into a module.

Are there any best practices for implementing this kind of pattern?

Is there an existing node module that does this? (the linked file seems like it could easily be a generic module in any node app)

Aucun commentaire:

Enregistrer un commentaire