receive updates from a set of keys and ranges in leveldb

npm install level-track
12 downloads in the last month


keep track of all the active queries from a request to route live updates

build status


In this example we'll subscribe to the range of keys "f" through "p" and the singular key "c". The database is then populated with random keys and values to show that only keys "f" through "p" inclusive and "c" are captured.

var sub = require('level-sublevel');
var db = sub(require('level')('test.db'));
var tracker = require('level-track')(db);
var through = require('through');

var t = tracker();


setInterval(function () {
    var l = Math.floor(Math.random() * 2) + 1;
    var key = '';
    for (var i = 0; i < l; i++) {
        key += String.fromCharCode(Math.random() * 26 + 97);
    db.put(key, { n: Math.floor(Math.random() * 100) });
}, 250);




The tracking protocol is newline-delimited json. Each line should match one of these formats:


Receive updates from a single key.


Receive updates from the range "startkey" through "endkey", inclusive.


Receive updates from the range "startkey" through "endkey", inclusive and populate the result stream with data from the exclusive "sincekey" through "endkey".

This form is useful so that no updates slip past due to delays from rendering the initial content and establishing a live connection.


var tracker = require('level-track')

var t = tracker(opts)

Return a duplex stream that expects input of the form documented in the protocol section and produces output of the form:


which is the same format that db.hooks and db.batch() use.

When opts.objectMode is true, output is written as objects. Otherwise, output is written as newline-delimited lines of json.

You may also specify an optional opts.keyMap(key) function to pre-transform keys. Return the value you want to use for the key.


With npm do:

npm install level-tracker



npm loves you