gaffer

0.0.6 • Public • Published

Gaffer

Gaffer is a package for NodeJS that handles execution stacks in a breeze!

  • Simple Json configuration file
  • Attach Gaffer to any server object
  • Execution order defined in a simple configuration array included in the Json config
  • Makes creating new applications easy by managing the transitions between critical application functions
  • Theatre nerds rejoice!

Simple Setup

Setting up Gaffer is quite simple. Add it to your package's dependencies, and it's simple after that!

server.js

var gaffer = require("gaffer"),
    express = require("express");

var app = express();
gaffer.init(app);

All apps that use Gaffer must have a config file. Plugins can access the config file by referencing sf.config at any point in time.

sf.config.json

{
    "plugins": [
        "database",
        "router",
        ... etc
    ]
}

Creating Plugins

The plugins array located inside the config file defines the plugin execution stack. Plugins are either directories or single .js files placed in the plugins directory.

The plugin's export should reference a function with 3 parameters.

  • sf - Gaffer's object passed through each plugin.
  • app - The express object passed to gaffer's init function at the start of your application.
  • next - Call this after everything's been complete in your plugin to move onto the next one.

Creating a plugin is simple, here's an exmaple of a database plugin, database.js:

exports = module.exports = function(sf, app, next) {
    
    sf.mongoose = require("mongoose");
    console.log("Starting connection to MongoDB...");
    sf.mongoose.connect(sf.config.mongoUri, function(err) {
        if (err) {
            console.log("DB Error!".red + " " + err);
            return;
        } else {
            console.log("\tDone!".blue + " We're connected.");
            next();
        }
    })

}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.6
    0
    • latest

Version History

Package Sidebar

Install

npm i gaffer

Weekly Downloads

0

Version

0.0.6

License

none

Last publish

Collaborators

  • spencersharkey