node package manager
Easy sharing. Manage teams and permissions with one click. Create a free org ยป



File-based key-value store. LightStore uses a quasi-JSON file as persistent storage for append-only, read-once use.


The redundant JSON format is the most basic file format that LightStore supports. It associates keys and values, keys being arbitrary strings, possibly repeated over the file. The format omits the closing curly brace or bracket, making it easily appendable.

Upon parsing, the closing brace or bracket is restored, and redundant key-value pairs will be reduced to the last key occurrence. For example, {"foo":"bar","hello":"world","foo":"BAR" will be parsed as {foo:"BAR", "hello":"world"}.


For storing more complex data formats, LightStore introduces a key-value store with a fixed key format. In a LightStore key-value store, Keys represent tree paths, in particular, serialized versions of sntls.Path. Changes made to the tree are simply appended to the file that builds on the previously introduced Rjson format. Upon parsing, the tree is re-constructed by applying the recorded changes in identical order.

    .write('foo>bar'.toPath(), {my: "value"});


For logical data manipulation, LightStore extends the versatile tree data structure from Sntls (sntls.Tree). Persisted trees behave the exact same way as ordinary Sntls trees in terms of querying and modification, the only difference being that changes by .setNode() will be appended to the specified file.


The following sample code loads a LS file, then (assuming loading has finished) queries employee keys grouped by first names and saves the results to ''.

var tree = lightstore.PersistedTree.create('')
// ...