fusion.io
fusion.io is fast and lightweight plugin system for Node.js applications. This module follows the philosophy everything's a plugin™, which effectively means that your whole application is just built on top of a bunch of plugins. They can interact and rely on each other, without worrying about dependency resolving & injection.
How it works
As mentioned above, the principle of fusion.io is that your whole application is built on top of some plugins. Worried about dependency resolving & injection? fusion.io handles these things for you!
License & Requirements
GPL v3 - Please see LICENSE for more information. No requirements except Node.js >= 0.6.x
Application skeleton
app.js
This is your main application file, which should be named app,js. Usually it should only contain around 5 lines, thanks to fusion.io:
var FusionIO = ;var app = ;app; // Specifies where the 'plugins' folder is located, usually __dirname is correctapp;app;
config.js
This file contains all active plugins and their configuration, if necessary. It should be loaded by loadConfig before creating the application. Currently, multiple configurations can NOT be merged together. Example configuration:
var exports = moduleexports = // How to require a plugin without any options pluginName: 'fusion-blog.db' // Shortcut to require plugins without any options 'fusion-blog.model' // Require a plugin with some options pluginName: 'fusion-blog.http' port: 8080 ;
plugins/
This is your plugin folder - each plugin should have its own folder within the plugins folder. To prevent duplicates, you should prefix your plugins with the project name, your vendor name or anything you like. Remember, you must specify the plugin name later on for dependency injection, so it shouldn't be too long.
Example: fusion-blog.db - fusion-blog is the product name, and db the plugin name.
Plugin skeleton
package.json
Every fusion.io plugin needs a package.json. It has two advances: First, you can easily use npm with your plugins. Second, all the required plugin dependencies and exports can be easily specified and changed. You interchanged a logging plugin with another one? Just edit the package.json to point to the new plugin. Example:
"name": "fusion-example.kitten-demo" // Optional metadata, can be used with NPM "version": "1.0.0" // Should always be specified! Otherwise fusion.io will log a warning. "main": "kitten.js" // Must point to the main plugin file "private": true // Optional metadata, can be used with NPM "fusionio": // Import 2 plugins, thats all you need to do... "imports": "fusion-blog.db" "fusion-example.kitten-milk" // Export one plugin (hint: you can export more than just one plugin) "exports": "fusion-example.kitten"
kitten.js
This file can have any name, as long as it is specified in the main property of the package.json file. As you might have guessed already, it represents your main plugin file, which should be built like this:
/** * This method gets called by the fusion.io core. There will always be exactly 3 arguments provided. * * exist, an error will be thrown. Signature: function(pluginName) * * If an error occured while initializing the plugin, pass the error to err. * If everything went fine, pass an object containing the plugins to export. * * the function 'fetchPluginList' is supported, which will return a list of all plugins with their versions. */ { var $db = ; var $milk = ; exportsnull 'fusion-example.kitten': { return $milk; } ; console; console;} // Exports the pluginvar exports = moduleexports = FusionPlugin;
fusion.io plugin system - © 2013 Pascal Mathis dev@snapserv.net