Websocket RPC+PUB/SUB library

npm install brokr
11 downloads in the last week
44 downloads in the last month

Build Status


brokr is a javascript RPC+PUB/SUB via Websocket library that you shouldn't use yet.

If you want to anyway, go get it with npm install brokr

I am quite serious with my versioning of this, so please install a specific version to avoid breaking your application.

I follow Semantic Versioning 2.0.*


In the browser

If you need to use Brokr in the browser, you can

  • Use the included connect middleware Brokr.middleware(url) to serve a browser friendly Brokr version.
  • Use the Brokr.browserify(callback) function to get the source as a string.
  • Use the included build tool. Simply run make build in the Brokr module root to build the brokr.web.js file.

Note that i am writing a better more optimised version exclusively for the browser, and that the current browser implementation works, but have a gigantic footprint.

The browser version will have it's own repository, will properly not be avaiable through npm.

Example with connect

Your node application (lets call it app.js):

var Brokr   = require('brokr')
  , connect = require('connect');

//let us choose a reasonable port number
var port = 4000;

 //Start a http.Server as you usually would
 //Here we are using connect() to take advantage of
 //brokr's built in middleware for serving the static client
var server =//our http.Server instance as returned by connect's .listen() method
    //serve the brokr source on requests to /brokr.js
    //serve the "public" directory as is (put your index.html here)
    //and start the webserver
console.log("listening on port "+port);

//create a new Brokr object, exposing a single method called ping
var brokr = new Brokr({
    ping: function (response) {
        //when client requests ping, send with no error and the string "pong"
        response(null, "pong");

//attach our brokr to our server instance using the .listen() method
//The listen method could also take a port number which would start
//a new server on that port
    console.log("brokr listening on port "+port);

Your ./public/index.html file:

<!DOCTYPE html>
        <title>Brokr web demo</title>
        <!-- request the brokr script -->
        <script src="/brokr.js"></script>
            var brokr = new Brokr();
            //connect to the server
            .then(function(connection){ //then, on connect
                                        //return a promise for a ping response
                return connection.request('ping');
            .then(function(response){   //then on response
                console.log("got ping response,", response);
            .then(function(){           //then return a promise to disconnect
                return brokr.disconnect();
            .done(); //and we are done
npm loves you