Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@stdarg
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stdarg/9588146 to your computer and use it in GitHub Desktop.
Save stdarg/9588146 to your computer and use it in GitHub Desktop.
var levelup = require('level')
var options = {
keyEncoding: 'binary'
}
//var key = 'name'
var key = 100
// 1) Create our database, supply location and options.
// This will create or open the underlying LevelDB store.
levelup('./mydb', options, function(err, db) {
if (err) throw err
// 2) put a key & value
db.put(key, 'LevelUP', function (err) {
if (err) return console.log('Ooops on put!', err.message) // some kind of I/O error
// 3) fetch by key
db.get(key, function (err, value) {
if (err) return console.log('Ooops on get!', err.message) // likely the key was not found
// ta da!
console.log(key + ' = ' + value)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment