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

v2.0.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 concepts:

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

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


Installation

npm install @jsonkit/db

Core Types

Identifiable

type Identifiable = { id: string }

All multi-entry databases require entries to have a string id.

Promisable<T>

A value or a promise of a value.

type Promisable<T> = T | Promise<T>

PredicateFn<T>

Used for filtering entries.

type PredicateFn<T extends Identifiable> = (entry: T) => boolean

DeleteManyOutput

Returned by bulk delete operations.

type DeleteManyOutput = {
  deletedIds: string[]
  ignoredIds: string[]
}

Multi-entry Databases

Multi-entry databases manage collections of entries keyed by id.

Common API (MultiEntryDb<T>)

All multi-entry implementations expose the same async API:

  • create(entry)
  • getById(id)
  • getByIdOrThrow(id)
  • getWhere(predicate, max?)
  • getAll(ids?)
  • getAllIds()
  • update(id, updater)
  • delete(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.


MultiEntryFileDb<T extends Identifiable>

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

import { MultiEntryFileDb } from '@jsonkit/db'

const db = new MultiEntryFileDb<User>('./data/users')

Behavior

  • Each entry is stored as <id>.json in the provided directory.
  • The directory is created implicitly as files are written.
  • IDs are validated to prevent path traversal by default.

Constructor

new MultiEntryFileDb<T>(dirpath, options?)

Options

| Option | Description | Default | | --------------- | -------------------------------------- | ------- | | noPathlikeIds | Reject IDs containing / or \ | true | | parser | Custom JSON parser ({ parse(text) }) | JSON |

Notes

  • Failed reads (missing file or invalid JSON) return null.
  • destroy() deletes the entire directory.
  • Intended for development, prototyping, and small datasets.

MultiEntryMemDb<T extends Identifiable>

An in-memory implementation backed by a Map.

import { MultiEntryMemDb } from '@jsonkit/db'

const db = new MultiEntryMemDb<User>()

Behavior

  • Fast, ephemeral storage.
  • Ideal for tests and short-lived processes.
  • destroy() clears all entries.

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.

Constructor

new SingleEntryFileDb<T>(filepath, parser?)
  • 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.

Example

type User = { id: string; name: string }

const users = new MultiEntryFileDb<User>('./users')

await users.create({ id: 'u1', name: 'Alice' })

await users.update('u1', (u) => ({ name: 'Alice Smith' }))

const allUsers = await users.getAll()

Use Cases

  • Rapid application prototyping
  • CLI tools
  • Small internal services
  • Tests and mocks
  • Configuration and state persistence

Non-goals

  • Concurrency control
  • High-performance querying
  • Large datasets
  • ACID guarantees

For these, a dedicated database is recommended.


License

MIT