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

@donkeylabs/bun-server-core

v0.1.0

Published

Bun server utilities - routing, database, caching, auth, and middleware

Readme

bun-server-core

Reusable building blocks for Bun-based Express services. The package wraps common infrastructure such as routing, rate limiting, instrumentation, OTP utilities, and caching so that application packages can stay focused on domain logic.

Features

  • Express bootstrapperServer wires up JSON parsing, raw body preservation, static assets, CORS, and request logging before attaching routers.【F:packages/bun-server-core/src/server.ts†L1-L46】【F:packages/bun-server-core/src/middleware/index.ts†L1-L87】
  • Router glueMagikRouter bridges core route definitions to Express handlers, injects contextual metadata, and enforces rate limits per-route via the shared cache.【F:packages/bun-server-core/src/router/index.ts†L1-L70】
  • Cache & rate limitingSimpleCache persists JSON payloads in SQLite and powers rate-limiting state with automatic cleanup timers.【F:packages/bun-server-core/src/cache/index.ts†L1-L73】
  • Database helpersbuildDB, buildInstrumentedDB, and buildMigrator encapsulate Bun-friendly SQLite/Kysely configuration and log slow queries for observability.【F:packages/bun-server-core/src/db/index.ts†L1-L46】【F:packages/bun-server-core/src/db/instrumentation.ts†L1-L27】
  • OTP utilities – Generate and validate TOTP secrets and QR codes for authenticator apps shared between API and frontend packages.【F:packages/bun-server-core/src/otp/otp.ts†L1-L18】
  • Centralized error handling – Translate thrown ApiErrors into HTTP responses and provide sane fallbacks for unexpected failures.【F:packages/bun-server-core/src/middleware/errors.ts†L1-L24】

Directory overview

packages/bun-server-core
├── src/
│   ├── cache/           # SQLite-backed cache + rate limit storage
│   ├── db/              # BunSqlite dialect helpers, migrations, instrumentation
│   ├── encryption/      # Symmetric encryption helpers (for secrets at rest)
│   ├── jwt/             # Token helpers mirrored on the frontend
│   ├── middleware/      # Logging, rate limiting, and error handling
│   ├── otp/             # TOTP utilities and QR generation
│   ├── router/          # MagikRouter implementation
│   ├── stats/           # Request/system metrics collector
│   └── test/            # Reusable testing harness for API packages
└── index.ts             # Barrel exports used by downstream packages

Scripts

This package exposes utilities and does not define runtime scripts. Tests are typically executed from downstream packages (such as the API) using the shared helpers.

Using the router helper

import { Server, MagikRouter } from "bun-server-core";
import { authRouter } from "core";

const server = new Server(dependencies, allowedOrigins);
const auth = new MagikRouter(authRouter, cache);

auth.handle("browserAuthentication", async (input, ctx) => {
  const session = await authModel.login(input, ctx);
  ctx.res.json(session);
});

server.registerRouter(() => auth);
server.listen(8000);

For advanced usage (instrumented databases, cron-powered services, caching strategies), see the API package README.