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

@jsonkit/db

v5.2.1

Published

Simple database using JSON and your local filesystem

Readme

@jsonkit/db

@jsonkit/db is a lightweight, zero-dependency database abstraction for rapid prototyping. It provides simple file based and in memory databases with consistent APIs, suitable for small applications, tooling, tests, and early-stage prototypes where setting up a full database would be unnecessary overhead.

The package exposes two core database types:

  • Single entry databases – manage exactly one JSON-serializable object.
  • Multi entry databases – manage collections of JSON-serializable objects keyed by an id.

Both concepts are available in file backed and in memory variants.

Goals

  • Simple backend prototyping
  • No dependancies

Non-goals

  • Concurrency
  • High performance
  • Transactions
  • Large datasets

For these, a dedicated database is recommended.

Installation

npm install @jsonkit/db

Multi entry Databases

Multi entry databases manage collections of entries keyed by id.

Common API (MultiEntryDb<T>)

All multi-entry implementations expose the same base methods:

  • create(entry)
  • getById(id)
  • getByIdOrThrow(id)
  • getWhere(predicate, pagination?)
  • getFirstWhere(predicate)
  • getFirstWhereOrThrow(predicate)
  • getAll(ids?)
  • getAllIds()
  • updateById(id, updater)
  • updateFirstWhere(predicate, updater)
  • updateWhere(predicate, updater, pagination?)
  • deleteById(id)
  • deleteByIds(ids)
  • deleteWhere(predicate)
  • exists(id)
  • countAll()
  • countWhere(predicate)
  • destroy()

Updates are partial merges, and changing an entry’s id during an update is supported.

Here are the major types that are used in MultiEntryDb methods:

// An entry's id must be a string or easily convertable into one
type Identifiable = { 
  id: string | number | {
    toString: () => string
  } 
}

// Used in search and filter methods in MultiEntryDbs
type PredicateFn<T extends Identifiable> = (entry: T) => boolean

type PaginationInput = {
  take: number
  page: number
}

// A function that updates an entry and returns a partial of the updated entry
export type UpdaterFn<T> = (entry: T) => Promisable<Partial<T>>

// The output of a `deleteMany` operation
type DeleteManyOutput = {
  deletedIds: string[]
  ignoredIds: string[]
}

MultiEntryFileDb<T>

A file-backed database where each entry is stored as its own JSON file.

import { MultiEntryFileDb } from '@jsonkit/db'

// Second argument is optional and is shown here with it's default values
const db = new MultiEntryFileDb<User>('./path/to/data/dir', {
  parser: JSON,
  indent: 2,
  noPathlikeIds: true,
  disableLogs: true,
})
  • Each entry is stored as <id>.json in the provided directory.
  • The directory is created implicitly as files are written.
  • Second constructor argument and allof it's fields are optional
  • IDs are validated to prevent path traversal by default. This can be disabled via the noPathlikeIds option.
  • parser option allows custom parsing of entry contents.

MultiEntryMemDb<T>

An in-memory implementation backed by a Map.

import { MultiEntryMemDb } from '@jsonkit/db'

const db = new MultiEntryMemDb<User>()

Behavior

  • Fast, ephemeral storage.
  • persist() saves all entries to disk.
  • load() reads entries from persistent storage created by persist().

Single entry Databases

Single entry databases manage exactly one value, often used for configuration or application state.

Common API (SingleEntryDb<T>)

  • isInited()
  • read()
  • write(entry | updater)
  • delete()

write supports either replacing the entry or partially updating it via an updater function.

SingleEntryFileDb<T>

Stores a single JSON object in a file.

import { SingleEntryFileDb } from '@jsonkit/db'

const db = new SingleEntryFileDb<AppConfig>('./config.json')

Behavior

  • Reads and writes a single JSON file.

  • isInited() checks file existence.

  • read() throws if the file does not exist.

  • parser defaults to JSON.

SingleEntryMemDb<T>

An in-memory single-value database.

import { SingleEntryMemDb } from '@jsonkit/db'

const db = new SingleEntryMemDb<AppConfig>()

Behavior

  • Optional initial value.
  • read() throws if uninitialized.
  • delete() resets the entry to null.

License

MIT