Socket
Book a DemoInstallSign in
Socket

clusterfuck

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clusterfuck

wip cluster management

latest
Source
npmnpm
Version
1.3.0
Version published
Maintainers
1
Created
Source

clusterfuck

WIP cluster management.

Build Status

Write your code once and use configuration to route your services together. You should be able to define whether cluster('foo') requires a local module or returns a http request to http://foo/ without touching code.

Every service is a Stream, so it works either required locally or over the network.

Example

var clusterfuck = require('clusterfuck');
var cluster = clusterfuck({
  '@mic/site-header': 'http://localhost:8000'
});

var header = cluster('@mic/site-header');
// over http
header().pipe(process.stdout);

var layout = cluster('@mic/site-layout');
// require()d locally
layout().pipe(process.stdout);

You can for example use minimist to inject service location through stdarg:

var minimist = require('minimist');
var clusterfuck = require('clusterfuck');
var cluster = clusterfuck(minimist(process.argv.slice(2)));

var header = cluster('@mic/site-header');
// over http
header().pipe(process.stdout);

var layout = cluster('@mic/site-layout');
// require()d locally
layout().pipe(process.stdout);

and launch via:

$ node server.js --@mic/site-header=http://localhost:8000

Adapters

If no mapping is provided for a service, it will simply be require()d.

HTTP

var cluster = clusterfuck({
  '@mic/site-header': 'http://header.mic.com'
});
var header = cluster('@mic/site-header');

header('section', { some: 'opts' }).pipe(process.stdout)

will result in this request to get a header stream:

GET http://header.mic.com/section?some=opts

Nested properties are supported via qs.

Caching

var cluster = clusterfuck({
  '@mic/site-header': {
    source: 'http://header.mic.com',
    cache: true
  }
});

var header = cluster('@mic/site-header');

header('a').pipe(process.stdout); // fill the cache
// ...
header('a').pipe(process.stdout); // use the cache
// ...
header('b').pipe(process.stdout); // new args -> new cache

Installation

$ npm install clusterfuck

API

var cluster = clusterfuck(map)

Create a cluster with given map from service names to remote locations.

cluster.events

EventEmitter, see Events.

var service = cluster(name)

Create a constructor for the service known as name.

service([args, ][opts])

Create a readable stream from service with optional string args and an array of opts.

Events

The following events will be emitted for every outgoing request (read: not a require()), and will have the following properties:

  • request
    • id
    • transport
    • url
  • response
    • id
    • transport
    • url
    • status

There is a simple debug logger included, set the environment variable CLUSTERLOG=true to enable it.

Example:

cluster.events.on('response', function(res){
  if (res.transport == 'http') console.log('GET %s %s', res.url, res.status);
});

License

MIT

FAQs

Package last updated on 02 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts