When you start a new TypeScript backend today, you usually face a split:
- Minimal edge frameworks (like Hono) give you zero dependencies and great portability, but you spend the first week wiring up validation, JWT/JWKS auth, password hashing, OpenAPI, rate limiting, queues, and OpenTelemetry.
- Full-featured frameworks (like NestJS or heavily-plugged Fastify) give you everything out of the box, but pull in dozens to hundreds of transitive npm dependencies and rarely run cleanly on Edge Workers or Deno.
I built BareJS to explore a third option: batteries-included for production, yet zero external runtime dependencies, running the same codebase across Bun, Node.js (uWebSockets.js / node:http), Deno 2, Cloudflare Workers, and AWS Lambda.
1. O(1) JIT Radix Routing — With Automatic No-JIT Fallback
BareJS compiles route trees and middleware pipelines at startup into specialized functions, eliminating per-request array allocations and dynamic lookups. On Bun, single-handler async routes use a Bun.peek fast-path to avoid redundant Promise wrappers.
One real-world constraint of JIT compilers is strict CSP environments or V8 launched with --disallow-code-generation-from-strings. BareJS probes dynamic code evaluation once at startup: if new Function is disallowed, it automatically falls back to interpreted Radix lookup, pipeline execution, and response projection — with zero EvalErrors and zero hot-path overhead when JIT is allowed.
2. Standard Schema v1 + Automatic Response Secret-Stripping
Accidental data leaks (returning passwordHash or internal DB columns) are one of the most common API security bugs. In BareJS, attaching a response schema (TypeBox, Zod, Valibot, or ArkType) compiles a field projector that automatically strips undeclared properties — whether you return a plain object or call return ctx.status(201).json(user).
import { BareJS, Type } from 'barejs'; const app = new BareJS().get('/users/:id', { response: Type.Object({ id: Type.String(), name: Type.String(), }), }, (ctx) => { return ctx.status(200).json({ id: ctx.params.id, name: 'Alice', passwordHash: 'argon2id$...', // automatically stripped }); }); 3. End-to-End Typed RPC (bareTreaty) + Typed SSE
bareTreaty(app) gives you a chained TypeScript client over HTTP or in-memory (zero network overhead for SSR and tests):
- Route parameters (
:id) are inferred at compile time even without schemas. - Inline per-route middlewares preserve full return-type inference.
-
ctx.sse<T>()returnsSseResponse<T>, whichbareTreatyunwraps asAsyncIterable<T>withAbortSignalcancellation.
4. Production Guardrails Built In
Rather than leaving edge cases to ad-hoc userland code, BareJS includes:
- LIFO Context Pooling +
ctx.detach(): Keeps GC pressure low on the hot path, guards against Use-After-Free in dev mode, and lets you safely detachctxfor background tasks in 1 call. - Scoped Resource Cleanup (
ctx.defer()&Symbol.asyncDispose): Guarantees DB connections/locks close in LIFO order after the response. - Multi-Node Scale via
BareStore: SharememoryStore,sqliteStore,upstashStore, or CloudflarekvStoreacrossrateLimit(),cache(),idempotency(),barejs/workflow, distributedapp.cron()locks, and persistentbarejs/queue(await queue.restore()). - Graceful Rolling Updates (
app.shutdownSignal): AnAbortSignalthat fires as soon asapp.drain()orapp.stop()begins, so long-lived SSE and AI streams close cleanly.
5. 18 Opt-In Modular Subpaths (0 Bytes When Unused)
Everything beyond core HTTP/WebSockets lives in dedicated subpath exports (barejs/edge, barejs/mcp, barejs/devtools, barejs/otel, barejs/store, barejs/workflow, barejs/queue, barejs/webhooks, barejs/metrics, barejs/ai, barejs/jsx, barejs/ssg, and serverless adapters for AWS Lambda, Cloudflare Pages, and Netlify).
Try It Out
bun create barejs my-app # or npm install barejs - GitHub: https://github.com/xarhang/bareJS
- Docs: https://xarhang.github.io/bareJS/
- Benchmarks: https://xarhang.github.io/bareJS/dev/benchmarks/
- AI / LLM Docs (
llms-full.txt): https://xarhang.github.io/bareJS/llms-full.txt
(Note: BareJS is an independent TypeScript web framework and is not affiliated with Holepunch's Bare JavaScript runtime.)