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

snapdbjs

v1.0.0

Published

A fast, lightweight, Redis-like in-memory database for Node.js with plugin and middleware support. Perfect for ephemeral data, rate limiting, OTPs, tokens, and more.

Readme

SnapDB

A lightweight, fast, in-memory key-value store for Node.js, inspired by Redis. Perfect for ephemeral data like rate limiting, OTPs, tokens, and feature flags—no external dependencies, minimal memory footprint.

Features

  • In-memory key-value store
  • Supports strings, numbers, and JSON-serializable values
  • Per-key TTL (time-to-live) and automatic expiry
  • Namespaced keys for isolation
  • Fully async API (Promise-based)
  • Configurable options (default TTL, cleanup interval)
  • TypeScript support out of the box

Install

npm install snapdb

Usage

import SnapDB from 'snapdb';

const db = new SnapDB({ defaultTTL: 60000 });

await db.set('otp:12345', '894023', 300000); // 5 min TTL
const otp = await db.get('otp:12345');

await db.del('otp:12345');
const exists = await db.exists('otp:12345'); // false

API

new SnapDB(options?)

  • defaultTTL (ms): Default TTL for keys (optional)
  • cleanupInterval (ms): How often to purge expired keys (default: 1000)
  • namespace: Prefix for all keys (optional)

Methods

  • set(key, value, ttl?): Store a value with optional TTL
  • get(key): Retrieve a value
  • del(key): Delete a key
  • exists(key): Check if a key exists
  • keys(pattern?): List of keys, optionally filtered (supports * wildcard)
  • ttl(key): Remaining TTL for a key (ms)
  • stats(): Returns { keys, memory }
  • close(): Stops background cleanup

Use Cases

  • Rate limiting
  • OTP/session/token storage
  • Feature flags
  • Temporary data for APIs

Limitations

  • Not for persistent or distributed storage
  • No clustering/replication
  • Memory usage scales with data

License

MIT

Plugin System

SnapDB supports a powerful plugin system for advanced use cases. Plugins can hook into lifecycle and data operations (set, get, del, etc.) and are fully typesafe.

Using Plugins

import SnapDB from 'snapdb';
import { LRUPlugin } from './plugins/plugin-lru';
import { PersistencePlugin } from './plugins/plugin-persistence';
import { MetricsPlugin } from './plugins/plugin-metrics';
import { EncryptionPlugin } from './plugins/plugin-encryption';

const db = new SnapDB({
  plugins: [
    LRUPlugin({ maxKeys: 1000 }),
    PersistencePlugin({ file: './snapdb.json' }),
    MetricsPlugin(),
    EncryptionPlugin({ passphrase: 'mysecret' })
  ]
});

Middleware System

SnapDB supports middleware for value transformation, validation, logging, and more. Middleware can be chained and is fully typesafe.

Using Middleware

import { JSONMiddleware } from './middleware/json-middleware';
import { LoggingMiddleware } from './middleware/logging-middleware';
import { ValidateMiddleware } from './middleware/validate-middleware';
import { CompressMiddleware } from './middleware/compress-middleware';

const db = new SnapDB({
  middleware: [
    JSONMiddleware(),
    LoggingMiddleware(),
    ValidateMiddleware({ key: k => k.length < 32, value: v => typeof v !== 'undefined' }),
    CompressMiddleware()
  ]
});

Provided Middleware

  • JSONMiddleware: Stringifies objects on set, parses on get.
  • LoggingMiddleware: Logs all set/get operations.
  • ValidateMiddleware: Enforces key/value constraints (configurable).
  • CompressMiddleware: Compresses string values on set, decompresses on get.

Provided Plugins

LRUPlugin

Evicts the least recently used key when a maximum number of keys is reached.

import { LRUPlugin } from './plugins/plugin-lru';
const lru = LRUPlugin({ maxKeys: 100 });

PersistencePlugin

Persists the database to disk (JSON) on every set/del and loads on startup.

import { PersistencePlugin } from './plugins/plugin-persistence';
const persistence = PersistencePlugin({ file: './snapdb.json' });

MetricsPlugin

Tracks operation counts and exposes a getMetrics() method on the SnapDB instance.

import { MetricsPlugin } from './plugins/plugin-metrics';
const metrics = MetricsPlugin();
// Usage: db.getMetrics()

EncryptionPlugin

Encrypts values at rest using a symmetric passphrase (AES-256-GCM).

import { EncryptionPlugin } from './plugins/plugin-encryption';
const encryption = EncryptionPlugin({ passphrase: 'mysecret' });

Type Safety

All plugins, middleware, and core APIs are fully typed with TypeScript for maximum safety and IDE support.