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

json-portable-db

v0.1.1

Published

High-performance file-backed JSON database with memory-first reads and atomic writes

Readme

json-portable-db

High-performance file-backed JSON database with memory-first reads and atomic writes.

Stores all data as a single JSON file on disk. All reads are served from an in-memory Map (O(1) by id); writes are debounced and persisted atomically via tmp + rename.

Motivation

Why choose this?

In modern development, we often fall into the "Infrastructure Botnet" trap: small applications that require a complex network of external services (DBaaS, cloud clusters, managed providers) just to function. This introduces unnecessary network latency, hidden costs, and fragility.

  • O(1) Reads: Serving data from an in-memory Map provides effectively zero latency (~0ms), outperforming any networked database.
  • Zero Infra: No servers, no configurations, no ports. Your database is a single, human-readable JSON file.
  • Total Portability: Perfect for local tools, CLIs, and apps where simplicity and speed are priority.

Install

npm install json-portable-db

Quick start

import { JsonPortableDB } from "json-portable-db";

type Repo = { id: number; name: string; status: string };

const db = new JsonPortableDB({ path: "./data/db.json", backup: true });
await db.connect();

const repos = db.collection<Repo>("repos");

repos.insert({ id: 1, name: "my-repo", status: "pending" });

await repos.upsert(1, { status: "completed" });

const repo = repos.get(1);         // O(1) by id
const found = repos.findOne(1);    // same, via overload
const byName = repos.findOne(r => r.name === "my-repo"); // O(n) scan

await db.flush();       // force immediate write
await db.disconnect();  // flushes pending changes before closing

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | path | string | — | Path to the JSON file (created if missing). | | backup | boolean | false | Keep up to 5 rotating backups (*.bak.1*.bak.5). | | debounceMs | number | 200 | Debounce interval for deferred writes (ms). |

API

JsonPortableDB

new JsonPortableDB(options: JsonPortableDBOptions)

Extends EventEmitter. Emits:

  • "saved"{ path: string } after each successful persist.
  • "error" — on I/O or serialization failures.

| Method | Description | |--------|-------------| | connect() | Loads the file (or starts empty). Must be called before collection(). | | collection<T>(name) | Returns a typed Collection<T>. Requires connect() first. | | flush() | Forces an immediate write if there are pending changes. | | disconnect() | Cancels the pending debounce and flushes before marking as disconnected. |

Collection<T extends { id: number }>

| Method / Prop | Description | |---------------|-------------| | insert(doc) | Inserts a shallow copy of doc. Throws on duplicate id. | | get(id) | O(1) lookup by primary key. | | findOne(id) | O(1) lookup by primary key (overload). | | findOne(predicate) | O(n) scan when no index applies. | | upsert(id, patch) | In-place Object.assign if exists; creates { id, ...patch } otherwise. | | entries() | Iterator over all rows (no clone). | | size | Number of rows in memory. |

Scale limits

| 🛡️ Current Status | | :--- | | Works correctly (Durable & Anti-Race Conditions). The performance limits are affirmed strictly by the number of elements. We are currently avoiding discussions regarding record sizes or the number of fields. |

[!IMPORTANT] The performance ranges below are based strictly on the number of elements (record count). We are currently avoiding considerations regarding the size of individual records or the number of fields.

| Range | Behavior | |-------|----------| | ≤ 10 000 records | Comfortable zone for connect, Map reads, and periodic flush. | | 10k – 50k | Still viable; a console.warn is emitted to monitor load and serialization times. | | > ~50 000 | High risk of memory pressure and slow JSON.stringify/parse; a warning recommends migrating to SQLite. |

When you need multiple indexes, partial queries without loading everything, or concurrent writers, consider SQLite (better-sqlite3, sql.js, etc.).

See PERFORMANCE.md for a detailed rationale of the design decisions.

Requirements

  • Node.js ≥ 18

License

MIT