Server used to relay deltas

npm install relay-server
22 downloads in the last month


build status dependency status

Server used to relay deltas


// Configure a server that takes arbitrary incoming messages and
// accepts them
var servers = RelayServer({
    // writeRoutes is where you configure how to handle incoming
    // requests to the write http server. You should
    // sanitize, authorize and validate the incoming message
    // and then return a triplet of { uri, verb, body }
    writeRoutes: {
        "/*": function acceptEverything(req, res, opts, callback) {
            var pathname = url.parse(req.url).pathname
            jsonBody(req, res, function (err, body) {
                if (err) {
                    return callback(err)

                callback(null, { uri: pathname, verb: req.method, body: body })
                sendJson(req, res, "ok")
    // readRoutes is where you configure how to read a consistent
    // state for a given uri. This will be the first value
    // flushed down the streaming connection followed by individual
    // messages
    readRoutes: {
        "/*": function returnNothing(req, pathname, opts, callback) {
            callback(null, {
                uri: pathname,
                verb: "PATCH",
                body: {}
    sharedHttp: true, // use a single HTTP server for write & read
    tcp: true // create a TCP server for write & read



There is a benchmark for the memory usage of the relay-server

There is also a benchmark for the CPU usaged of the relay mechanism using plain TCP. They are locationed in ./benchmarks/plain-tcp

On my machine the following

Print out that the server uses roughly 30% CPU & 20MB and the client uses 40$ CPU & 10MB

As can be seen the memory usage of this relaying is completely flat. However the CPU usage seems really high.

Improvements (soon)

  • I have yet to figure out why the CPU usage is high


npm install relay-server


  • Raynos

MIT Licenced

npm loves you