by substack

substack / shoe

streaming sockjs for node and the browser

429 Stars 44 Forks Last release: Not found Other 42 Commits 15 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


Streaming sockjs for node and the browser.

This is a more streaming, more unixy take on sockjs.

shoe point javascript


stream all the things

Browser code that takes in a stream of 0s and 1s from the server and inverts them:

var shoe = require('shoe');
var through = require('through');

var result = document.getElementById('result');

var stream = shoe('/invert'); stream.pipe(through(function (msg) { result.appendChild(document.createTextNode(msg)); this.queue(String(Number(msg)^1)); })).pipe(stream);

Server code that hosts some static files and emits 0s and 1s:

var shoe = require('shoe');
var http = require('http');

var ecstatic = require('ecstatic')(__dirname + '/static');

var server = http.createServer(ecstatic); server.listen(9999);

var sock = shoe(function (stream) { var iv = setInterval(function () { stream.write(Math.floor(Math.random() * 2)); }, 250);

stream.on('end', function () {

stream.pipe(process.stdout, { end : false });

}); sock.install(server, '/invert');

The server emits 0s and 1s to the browser, the browser inverts them and sends them back, and the server dumps the binary digits to stdout.

By default, there's no logspam on stdout to clutter the output, which is a frustrating trend in realtimey websocket libraries that violates the rule of silence.

Just wait for a client to connect and you'll see:

$ node server.js

with dnode

Since dnode has a simple streaming api it's very simple to plug into shoe.

Just hack up some browser code:

var shoe = require('shoe');
var dnode = require('dnode');

var result = document.getElementById('result'); var stream = shoe('/dnode');

var d = dnode(); d.on('remote', function (remote) { remote.transform('beep', function (s) { result.textContent = 'beep => ' + s; }); }); d.pipe(stream).pipe(d);

and hack up a server piping shoe streams into dnode:

var shoe = require('shoe');
var dnode = require('dnode');

var http = require('http'); var ecstatic = require('ecstatic')(__dirname + '/static');

var server = http.createServer(ecstatic); server.listen(9999);

var sock = shoe(function (stream) { var d = dnode({ transform : function (s, cb) { var res = s.replace(/[aeiou]{2,}/, 'oo').toUpperCase(); cb(res); } }); d.pipe(stream).pipe(d); }); sock.install(server, '/dnode');

Then open up

in your browser and you should see:
beep => BOOP

with express or connect

you must pass the return value of

var shoe = require('shoe');

var express = require('express') var app = express()

var sock = shoe(function (stream) { ... });

// *** must pass expcess/connect apps like this: sock.install(app.listen(9999), '/dnode');

with reconnect

you can use reconnect just in case your sock ends or gets disconnected.

var shoe = require('shoe');
var reconnect = require('reconnect');
var es = require('event-stream');
var result = document.getElementById('result');

var r = reconnect(function (stream) {

var s = es.mapSync(function (msg) { result.appendChild(document.createTextNode(msg)); return String(Number(msg)^1); }); s.pipe(stream).pipe(s);


browser methods

var shoe = require('shoe')

var stream = shoe(uri, cb)

Return a readable/writable stream from the sockjs path

may be a full uri or just a path.

will emit a
event when the connection is actually open, (just like in net). writes performed before the
event will be buffered. passing in
to shoe is a shortcut for
shoe(uri).on('connect', cb)

server methods

var shoe = require('shoe')

All the methods from the sockjs exports objects are attached onto the

function, but the
function itself is special.

var sock = shoe(opts, cb)

Create a server with

except this function also adds the
function below.


is specified, it fires

sock.install(server, opts)


with the default option of spamming stdout with log messages switched off in place of just emitting
messages on the
object instead. This is a much less spammy default that gets out of your way.


is a string, use it as the

server events

All the messages that sockjs normally emits will be available on the

object plus the events below:

sock.on('log', function (severity, msg) { ... })

Using the default logger with

will cause these
messages to be emitted instead of spamming stdout.


With npm do:

npm install shoe



We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.