Skip to content

richtera/hook.io

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hook.io is a distributed EventEmitter built on node.js. In addition to providing a minimalistic event framework, hook.io also provides a rich network of hook libraries for managing all sorts of input and output.

"hooks" provide a very simple and light way to extend an application to seamlessly communicate with other "hook" enabled devices. By design, extending legacy applications to communicate with hook.io is very easy.

hook.io applications are usually built by combining together several smaller "hooks" to compose new functionality in a distributed and organized way.

Features :

  • Build large, decoupled, distributed, and fault tolerant I/O heavy applications in node.js
  • Create hooks on ANY device that supports JavaScript (cross-browser support via socket.io)
  • Spawning and Daemonizing of processes handled with Forever
  • Messaging API inherits and mimics Node's native EventEmitter API (with the help of EventEmitter2)
  • Interprocess Message Publishing and Subscribing done through EventEmitter2 and dnode
  • Easily scale any tcp based messaging infrastructure (such as clustering socket.io chat rooms in memory)
  • Easily connect / disconnect hooks "hot" without affecting other services

Additional Resources

Installation

 [sudo] npm install hook.io -g

Start a hook

hookio

auto-discovery will now create a hook server if this is your only running hook

Connect another hook

hookio

you now have two hooks connected to each other

This is the most minimal hook.io application you can have. It does nothing. No cruft, no extra baggage.

Connect another hook! With a REPL!

hookio --repl

you now have three hooks connected to each other

Extending your hook.io mesh

At this point, you've got 3 nodes talking to each other, and an interactive repl to run hook.emit and hook.on commands. Now you can extend your network of hooks using any of the existing hook libraries, or by extending from the base Hook object. You can now fire messages cross-process, cross-platform, and cross-browser.

How about Unix Pipes?

Pipe STDIN to hookio

tail foo.txt -f | hookio 

hook.io will now emit STDIN data as separate hook.io events

Pipe hook.io events to STDOUT

hookio -p | less

Using the -p option, hook.io will stream events to STDOUT as \n delimited JSON documents. Each document represents a single hook.io event.

example STDOUT:

{"name":"the-hook","event":"the-hook::sup","data":{"foo":"bar"}}

Multicast DNS ( mdns )

Multicast DNS (mdns) is a way of using DNS programming interfaces, packet formats and operating semantics on a small network where no DNS server is running. The mDNS protocol is used by Apple's Bonjour and Linux Avahi service discovery systems. mdns is an easy way to help networked devices find each other without any prior configuration.

hook.io has built-in experimental mdns support. This is intended to work on all operating systems and is intented for a way to providezero configuration networking discovery and connection of hooks over a Local Area Network ( LAN )

IMPORTANT

Before you can use the mdns feature, you will need to install a few additional dependencies.

 npm install mdns@0.0.4

MacOS and Windows should work out of the box. If you are running Linux, you may need to install the following libraries.

 apt-get install libavahi-compat-libdnssd-dev

using mdns

Computer 1

 hookio -m

Computer 2

hookio -m

Now these two computers ( connected over a LAN, with no central DNS server ) will automatically discovery each other and begin to transmit messages. Think of the possibilities!

Available Hooks (more coming soon)

Hook Library wiki: https://github.com/hookio/hook.io/wiki/Hook.io-Libraries

You can also search http://search.npmjs.org/ for "hook.io" ( although there are so many matches already, the search interface can't display them all.. )

  • cron: Adds and removes jobs that emit hook.io events on a schedule
  • couch: Emit hook.io events based on your CouchDB _changes feed
  • irc: Full IRC bindings
  • helloworld
  • logger: Multi-transport Logger (Console, File, Redis, Mongo, Loggly)
  • hook.js: Build web apps / use hook.io in any browser
  • mailer: Sends emails
  • sitemonitor: A low level Hook for monitoring web-sites.
  • request: Simple wrapper for http://github.com/mikeal/request
  • twilio: Make calls and send SMS through Twilio
  • twitter: Wrapper to Twitter API
  • webhook: Emits received HTTP requests as hook.io events (with optional JSON-RPC 1.0 Support)
  • wget: Downloads files using HTTP. Based on the http-get module by Stefan Rusu
  • tar: A hook to wrap around tar
  • gzbz2: A hook for compressing and uncompressing files
  • mock: A hook that mocks messages. Useful for hook.io related development.

Using hook.io programmatically

Note: This is only one, small, example.

see examples folder for extensive example code

to see all other supported types of hook messaging ( including EventEmitter and Callback style ), see: https://github.com/hookio/hook.io/tree/master/examples/messaging

var Hook = require('hook.io').Hook;

var hookA = new Hook({
  name: "a"
});

hookA.on('*::sup', function(data){
  // outputs b::sup::dog
  console.log(this.event + ' ' + data);
});

// Hook.start defaults to localhost
// it can accept dnode constructor options ( for remote connections )
// these hooks can be started on diffirent machines / networks / devices
hookA.start();

var hookB = new Hook({
  name: "b"
});

hookB.on('hook::ready', function(){
  hookB.emit('sup', 'dog');
});

hookB.start();

Tests

All tests are written with vows and require that you link hook.io to itself:

  $ cd /path/to/hook.io
  $ [sudo] npm link
  $ [sudo] npm link hook.io
  $ npm test
  • Marak (Marak Squires)
  • indexzero (Charlie Robbins)
  • jesusabdullah (Joshua Holbrook)
  • temsa (Florian Traverse)
  • mmalecki (Maciej Małecki)
  • jamesonjlee (Jameson)
  • pksunkara (Pavan Kumar Sunkara)
  • Marsup (Nicolas Morel)
  • mklabs (Mickael Daniel)
  • Tim-Smart (Tim)
  • stolsma (Sander Tolsma)
  • sergeyksv
  • thejh (Jann Horn)
  • booyaa (Mark Sta Ana)
  • perezd (Derek Perez)
  • ejeklint (Per Ejeklint)
  • emilisto (Emil Stenqvist)
  • vns
  • mwawrusch (Martin Wawrusch)
  • AvianFlu (Charlie McConnell)

MIT License

Copyright (c) Nodejitsu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

a distributed EventEmitter and i/o framework for node.js

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%