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 🙏

© 2025 – Pkg Stats / Ryan Hefner

noob-json-db

v1.0.3

Published

A JSON based Database for Node.js

Readme

noob-json-db

A lightweight, type-safe JSON database for Node.js, built with effect for robust functional error handling.


✨ Features

  • Simple JSON file persistence.
  • Basic CRUD operations.
  • Uses effect for powerful async and error handling.
  • Async API with createJsonDb wrapper for easier usage with async/await.
  • Written in TypeScript with full types.

📦 Installation

npm install noob-json-db

🛠️ Usage

import { createJsonDb } from "noob-json-db";

type Book = {
  id: number;
  title: string;
};

async function main() {
  const db = createJsonDb<Book>("books.json");

  await db.addMany([
    { id: 1, title: "Svelte for Dummies" },
    { id: 2, title: "Vue for Dummies" },
    { id: 3, title: "React for Dummies" },
  ]);

  const books = await db.getAll();
  console.log("Books:", books);
}

main().catch(console.error);

📖 API

The core database class is JsonDb<T>, which returns Effect-based results. For ease of use, we recommend using the async wrapper:

createJsonDb<T>(filename: string): Asyncified<JsonDb<T>>

It creates a JSON database instance with asynchronous methods returning promises instead of effects.

Methods available on the async wrapper:

| Method | Signature | Description | | ------------ | ------------------------------------------------------------ | --------------------------------------------------- | | add | (item: T) => Promise<void> | Add a single item (fails if duplicate id). | | addMany | (items: T[]) => Promise<void> | Add multiple items (fails if duplicate ids). | | get | (n: number) => Promise<T[]> | Get first n items. | | getAll | () => Promise<T[]> | Get all items. | | getBy | (query: Partial<T>) => Promise<T[]> | Get items matching query. | | update | (query: Partial<T>, update: Partial<T>) => Promise<number> | Update items matching query; returns count updated. | | updateById | (id: T["id"], update: Partial<T>) => Promise<boolean> | Update item by id; returns success status. | | deleteById | (id: T["id"]) => Promise<boolean> | Delete item by id; returns success status. | | clear | () => Promise<void> | Clear all items. |


🔄 How createJsonDb Works

The createJsonDb function wraps the JsonDb class using a JavaScript Proxy. This proxy intercepts method calls, detects if they return an Effect, and automatically runs them as promises. Makes it possible to use async/await syntax seamlessly.

flowchart TD
    A["Call: await db.add(item)"] --> B["Proxy intercepts 'add'"]
    B --> C["Returns wrapped function"]
    C --> D["Calls target.add(item)"]
    D --> E["JsonDb.add returns an Effect"]
    E --> F{"Is result an Effect?"}
    F -- Yes --> G["Run with Effect.runPromise"]
    G --> H["Return Promise to caller"]
    F -- No --> I["Return result directly"]

🛠️ Development

npm run dev       # Run with watch mode using tsx
npm run build     # Compile TypeScript to lib/
npm run test      # Run tests with vitest
npm run test:ui   # Run vitest UI

📄 License

This project is licensed under the MIT License.