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 400,000 packages pre-installed, including node-red-contrib-leveldb-ttl with all npm packages installed. Try it out:

node-red-contrib-leveldb-ttl lists no main file and has no index.js, so it can't be directly required. If this is a mistake, please let us know. It may however contain internal files that you can require manually:

// require("node-red-contrib-leveldb-ttl/[??]")

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

node-red-contrib-leveldb-ttl v0.0.3

Support for TTL, streams, batch - LevelDB database

06 Oct 2015 - node-red-contrib-leveldb-ttl


Run the following command in the root directory of your Node-RED install

npm install node-red-contrib-leveldb-ttl


npm install git://


This is a quick and dirty Node-RED package to add Level-ttl support to the original node-red-node-leveldb code (version 0.0.5), and to wrap some Levelup functions, like batch and streams.

Use one node to either put (store) the msg.payload to the named database file, using msg.topic as the key, or to delete information select delete in the properties dialogue and again use msg.topic as the key..

Use the other node to get, or retrieve the data already saved in the database.

Again use msg.topic to hold the key for the database, and the result is returned in msg.payload. If nothing is found for the key then null is returned.

The configuration node allows to set the database Default TTLin seconds (0: disabled), and Scan TTL to set the internal scan in seconds. The Default TTL can be overriden.

The node to get from the database works as the original.

Some info about the new nodes:

Stream node: The configuration of this node defines the default type of stream: ReadStream, KeyStream or ValueStream. This can be overriden using msg.payload.keys and msg.payload.values. The range of keys that are streamed can be set by using msg.payload.start, msg.payload.end,, or msg.payload.limit. If no options are passed, it streams the entire database. Example: msg.payload = { keys: true, values: false, start: 'key1~', end: 'key1~~' } Stream2 node: it returns all results in one message.

Batch node: can be used for very fast bulk-write operations (both put and delete). msg.payload should contain a list of operations to be executed sequentially, although as a whole they are performed as an atomic operation inside LevelDB. Example: msg.payload =[ {type: 'put', key: 'key1', value: 123}, {type: 'del', key: 'key2'} ]

Batch2 node: This node get individuals operations and push them in a buffer before doing the batch operation to the database. The configuration of this node allows to set the buffer size.

KeyTTL node: This node can serve to insert or update a ttl for any given key from msg.topic in the database (even if that key doesn't exist but may in the future).

The configuration of the nodes to put, to batch and the keyttl node, include a Node TTL parameter to override the Default TTL. Also, Node TTL can be individually overriden by a msg.ttl.

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