npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

jodb

v0.1.2

Published

Flat JSON file database with promise

Readme

jodb NPM version Build Status

Need a quick way to get a local database?

Example

var jodb = require('jodb')
var db = jodb('db.json')

db('posts').push({ title: 'jodb is awesome'})

Database is automatically saved to db.json

{
  "posts": [
    { "title": "jodb is awesome" }
  ]
}

You can query and manipulate it using any lodash method

db('posts').find({ title: 'jodb is awesome' })

Install

npm install jodb --save

Features

  • Small
  • Serverless
  • lodash rich API
  • In-memory or disk-based
  • Hackable (mixins, id, encryption, ...)

It's also very easy to learn and use since it has only 8 methods and properties.

API

jodb([filename, options])

Creates a disk-based or in-memory database instance. If a filename is provided, it loads or creates it.

var db = jodb()          // in-memory
var db = jodb('db.json') // disk-based

When a filename is provided you can set options.

var db = jodb('db.json', {
  autosave: true, // automatically save database on change (default: true)
  async: true,    // asynchronous write (default: true)
  promise: false  //promise write(default: false)
})

jodb.stringify(obj) and jodb.parse(str)

Overwrite these methods to customize JSON stringifying and parsing.

db._

Database lodash instance. Use it for example to add your own utility functions or third-party libraries.

db._.mixin({
  second: function(array) {
    return array[1]
  }
})

var song1 = db('songs').first()
var song2 = db('songs').second()

db.object

Use whenever you want to access or modify the underlying database object.

if (db.object.songs) console.log('songs array exists')

db.save([filename])

Saves database to file.

var db = jodb('db.json')
db.save() // saves to db.json
db.save('copy.json')

Note: In case you directly modify the content of the database object, you'll need to manually call save

delete db.object.songs
db.save()

db.saveSync([filename])

Synchronous version of db.save()

Guide

Operations

With jodb you get access to the entire lodash API, so there's many ways to query and manipulate data. Here are a few examples to get you started.

Please note that data is returned by reference, this means that modifications to returned objects may change the database. To avoid such behaviour, you need to use .cloneDeep().

Also, the execution of chained methods is lazy, that is, execution is deferred until .value() is called.

Sort the top five songs.

db('songs')
  .chain()
  .where({published: true})
  .sortBy('views')
  .take(5)
  .value()

Retrieve song titles.

db('songs').pluck('title')

Get the number of songs.

db('songs').size()

Make a deep clone of songs.

db('songs').cloneDeep()

Update a song.

db('songs')
  .chain()
  .find({ title: 'jodb!' })
  .assign({ title: 'hi!'})
  .value()

Remove songs.

db('songs').remove({ title: 'jodb!' })

Id support

Being able to retrieve data using an id can be quite useful, particularly in servers. To add id-based resources support to jodbdb, you have 2 options.

underscore-db provides a set of helpers for creating and manipulating id-based resources.

var db = jodb('db.json')

db._.mixin(require('underscore-db'))

var songId = db('songs').insert({ title: 'jodb!' }).id
var song   = db('songs').getById(songId)

uuid returns a unique id.

var uuid = require('uuid')

var songId = db('songs').push({ id: uuid(), title: 'jodb!' }).id
var song   = db('songs').find({ id: songId })

Encryption support

In some cases, you may want to make it harder to read database content. By overwriting, jodb.stringify and jodb.parse, you can add custom encryption.

var crypto = require('crypto')

var cipher = crypto.createCipher('aes256', secretKey)
var decipher = crypto.createDecipher('aes256', secretKey)

jodb.stringify = function(obj) {
  var str = JSON.stringify(obj)
  return cipher.update(str, 'utf8', 'hex') + cipher.final('hex')
}

jodb.parse = function(encrypted) {
  var str = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8')
  return JSON.parse(str)
}

Changelog

See details changes for each version in the release notes.

Limits

jodbdb is a convenient method for storing data without setting up a database server. It's fast enough and safe to be used as an embedded database.

However, if you need high performance and scalability more than simplicity, you should stick to databases like MongoDB.

License

MIT - Typicode