Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including level-range with all npm packages installed. Try it out:

var levelRange = require("level-range")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

level-range v0.0.0

Find all K/V-pairs prefixed by a certain key.


Find all K/V-pairs prefixed by a certain key.

An often used range query when working with leveldb.


Given this data stored in a leveldb at /tmp/db:

  "bucket:a-bucket:0" : "some",
  "bucket:a-bucket:1" : "test",
  "bucket:a-bucket:2" : "data",
  "bucket:another-one:0" : "nope"

and a script test.js that takes argv and outputs found data:

var levelup = require('levelup');
var db = levelup('/tmp/db');
var JSONStream = require('JSONStream');
var range = require('level-range');

range(db, 'bucket:%s:', process.argv[2])

The output will be:

$ node test.js a-bucket

$ node test.js another-bucket


range(db, prefix, args...)

Create a range stream. args will be fed into util.formt together with prefix so you can use placeholders there.


With npm do:

$ npm install level-range



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free