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

shelfdb-cli

v0.1.0

Published

ShelfDB — a tiny self-hosted JSON document database with REST API and CLI

Downloads

3

Readme

ShelfDB — Tiny JSON Document DB

ShelfDB is a tiny self-hosted JSON document database with an append-only journal, periodic compaction, REST API, and CLI. No external dependencies; just clone, install, and run.

Features

  • Fastify REST API
  • Append-only journal with safe atomic snapshot compaction
  • Backups and restore (.json.gz)
  • CLI for serve, import/export, query, and maintenance
  • Optional write auth via SHELFDB_TOKEN
  • Optional CORS via SHELFDB_CORS=true

Requirements

  • Node.js 20+

Install

  • Local: npm install && npm run build
  • Global: npm install -g shelfdb-cli

Run

  • Local: ./bin/shelfdb serve --port 3000 or npm start
  • Global: shelfdb serve --port 3000

Data Location

  • Snapshot: data/shelfdb.json
  • Journal: data/shelfdb.journal.ndjson
  • Backups: backups/*.json.gz

REST API

  • GET /health
  • GET /db → list collections
  • GET /db/:collection → query docs (?q, ?limit, ?offset, ?sort)
  • POST /db/:collection → insert doc
  • GET|PUT|PATCH|DELETE /db/:collection/:id
  • POST /db/:collection/_bulk → atomic bulk ops
  • POST /export / POST /import (JSON or NDJSON)

Auth and CORS

  • Set SHELFDB_TOKEN=... to require write operations to include Authorization: Bearer <token> or ?token=<token>
  • Set SHELFDB_CORS=true to allow cross-origin clients

CLI

  • shelfdb serve [--port 3000] [--host 0.0.0.0] [--cors] [--token TOKEN]
  • shelfdb put <collection> <file> (JSON array or NDJSON)
  • shelfdb get <collection> [--query Q] [--limit N] [--offset N] [--sort field[:asc|desc]]
  • shelfdb del <collection> <id>
  • shelfdb compact
  • shelfdb backup
  • shelfdb restore <file>
  • shelfdb info

Examples (curl)

  • curl http://localhost:3000/health
  • curl http://localhost:3000/db
  • curl -X POST http://localhost:3000/db/books -H "Content-Type: application/json" -d '{"title":"Dune","author":"Frank Herbert"}'
  • curl http://localhost:3000/db/books?q=Herbert&limit=5&sort=title:asc
  • curl http://localhost:3000/db/books/<id>
  • curl -X PATCH http://localhost:3000/db/books/<id> -H "Content-Type: application/json" -d '{"rating":5}'
  • curl -X DELETE http://localhost:3000/db/books/<id>
  • Bulk: curl -X POST http://localhost:3000/db/books/_bulk -H "Content-Type: application/json" -d '[{"op":"insert","doc":{"title":"Dune"}},{"op":"insert","doc":{"title":"Foundation"}}]'
  • Export JSON: curl -X POST http://localhost:3000/export
  • Export NDJSON: curl -X POST 'http://localhost:3000/export?format=ndjson'
  • Import JSON: curl -X POST http://localhost:3000/import -H 'Content-Type: application/json' --data '{"collections":{"books":{}}}'
  • Import NDJSON: curl -X POST http://localhost:3000/import -H 'Content-Type: application/x-ndjson' --data-binary @data.ndjson

Examples (CLI)

  • ./bin/shelfdb serve --port 3000
  • ./bin/shelfdb put books samples/books.json
  • ./bin/shelfdb get books --query Herbert --sort title:asc
  • ./bin/shelfdb del books <id>
  • ./bin/shelfdb compact
  • ./bin/shelfdb backup
  • ./bin/shelfdb restore backups/backup-2024-01-01.json.gz
  • ./bin/shelfdb info

Docker

  • Build: docker build -t shelfdb .
  • Run: docker run -p 3000:3000 -v $(pwd)/data:/app/data -v $(pwd)/backups:/app/backups shelfdb
  • Compose: docker-compose up --build

License MIT License