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.