Question

I come from a PHP/Laravel backround, but my team has is leaning heavily toward using Node.js (and sails) for our next project, a collaboration studio of sorts for scholars. However, before I take the plunge, I have a question about best-practice for creating laravel style service providers (or wordpress style plugins) for a node.js application.

When loading a service provider in laravel 4.1, the class is loaded at a certain point, the boot() method is called, and the provider can "hook" into the events that are fired in runtime. The list of service providers is pulled from an array in a config file (though getting them from a database would be just as easy, as with wordpress).

Essentially, what I am looking for is the Node.js equivalent of this PHP code:

// Get an array of installed plugins from a config file (or database)
$exts = require_once 'config/installed_plugins.php';

/*
 * The $exts array looks like this $ext['class_name'] = '/plugin/file/path.php'
 * and each plugin file is a class with a boot() method that registers events 
 * with callbacks 
 */

// Iterate and boot each plugin
foreach ($ext as $class=> $path) {
    require $path;
    $c = new $class();
    $c->boot();  // Now this plugins events have been registered
}

Obviously this pseudo-code has a lot of security holes, and is not for production, but I think it makes my point.

I know (and love) Javascript's event-driven nature, so I imagine is is easy to implement something similar using Node.js, but I can't find where or how to load my service providers and allow them to hook into the execution.

Was it helpful?

Solution

js-plugins is an extension-point based open plugin framework.

It's rather inspired by Eclipse plugin system and I hope it's akin to what you are searching:

  • A host just requires js-plugins to manage plugins
  • A plugin need only a special section in package.json describing what it provides.

Relevant host side features as of your request:

  • Plugin registration
  • Directory scan (for plugins' package.json)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top