node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


rawr (a.k.a. RAWRpc)


Build Status Coverage Status

Remote Procedure Calls (JSON-RPC) sent over any EventEmitter transport.



npm install rawr

Using the RPC client

Every rawr client can act as both a client and a server

var rawr = require('rawr');
var client = rawr.init({
  sendEmitter : anEventEmitter,
  sendTopic : 'rpcCall',
  receiveEmitter : anEventEmitter,
  receiveTopic : 'rpcResponse',
  timeout: 5000 // timeout the call after 5 seconds, default is 10
// call an rpc method with a parameter and get a promise:
client.rpc('talk', 'luis')
  .then(function(result) {
    console.log(result); // prints 'hello, luis'

A rawr instance acting as an RPC server

var rawr = require('rawr');
var server = rawr.init({
  sendEmitter : anEventEmitter,
  sendTopic : 'rpcResponse', // the opposite of client
  receiveEmitter : anEventEmitter,
  receiveTopic : 'rpcCall' // the opposite of the client
function talkToMe(name) {
  // could return a value, a promise, or throw an error
  return 'hello, ' + name;
server.addMethod('talk', talkToMe);

Handling Notifications

Both the client and server can send each other notifications:

client.notifications.on('yo', function(who) {
  console.log(who); //prints 'dawg'
server.notify('yo', 'dawg');