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

@barqel/barq

v1.0.3

Published

Zero dependencies. Maximum performance. HTTP for Bun and Node.js; native WebSockets for Bun.

Readme

Barq

Barq is a high-performance HTTP core for Bun and Node.js, written in TypeScript. It provides a segment-trie router, typed route parameters, middleware hooks, request context helpers, cookie utilities, redirects, and graceful server shutdown. Native WebSocket support is available on Bun.

Requirements

  • Bun 1.1 or newer, or Node.js 18+ for HTTP applications. On Node.js, import @barqel/barq/node to enable the HTTP adapter; native WebSockets and Bun-specific server features require Bun.
  • A signing secret only when using signed cookies. Store it in a secret manager or environment variable; do not commit it.

Quick start

import { App, json } from "@barqel/barq";

const app = new App();

app.get("/users/:id", (ctx) => {
  return json({ id: ctx.params.id });
});

app.listen(3000);

This example enables the Node.js HTTP adapter. With Bun, import from @barqel/barq instead. Barq's native WebSocket routes require Bun.

See examples/README.md for runnable examples covering routing, middleware, validation, cookies, WebSockets, errors, and server lifecycle.

See compares/README.md for the separate Bun project used to benchmark Barq against Elysia with Bun's client or external oha.

The bilingual Fumadocs site lives in doc/. Run it with cd doc && bun run dev; English and Arabic docs are available at /en/docs and /ar/docs.

Unsigned cookies work without a signing secret. Cookies are HttpOnly by default; pass httpOnly: false only when browser JavaScript needs access. Set secure: true for HTTPS deployments. To use signed cookies, configure a high-entropy secret and set cookies with ctx.cookies.setSigned(name, value). getSigned returns null when verification fails or no secret is configured.

Incoming cookies are parsed lazily on the first ctx.cookies read or mutation. Routes that never use cookies do not parse the Cookie header or allocate the parsed-cookie map.

Error details are hidden by default unless development: true or NODE_ENV=development is set. Set development mode deliberately; error messages and stack traces can disclose application internals.

Routing and middleware

Routes support named parameters (/users/:id), optional parameters (/posts/:id?, up to eight per pattern), and final wildcards (/files/*path). Route groups add prefixes and middleware:

app.group("/api", { before: (ctx) => {
  if (!ctx.req.headers.has("authorization")) {
    return new Response("Unauthorized", { status: 401 });
  }
} }, (api) => {
  api.get("/health", () => json({ ok: true }));
});

Middleware before hooks may return a Response to short-circuit; after hooks can replace the response. Errors become HTTP responses and can be customized with app.onError().

For typed request state, return an object from a middleware before hook and keep the typed app returned by .use():

const app = new App()
  .use({ before: () => ({ user: { id: "user-1" } }) })
  .get("/me", (ctx) => json({ id: ctx.state.user.id }));

The object is merged into ctx.state at runtime; hooks returning void add no merge work. Chain .use(first).use(second) when the second middleware needs the first middleware's inferred state. validateJson(schema, handler) adapts any schema with a parse(unknown) method without adding a schema dependency:

app.post("/users", validateJson(userSchema, (_ctx, body) => json(body)));

Optional parameters are expanded into ordinary trie routes during registration. The matcher has no optional-route branch at request time; registration parses the original pattern once and reuses its segments. Run bun run bench for warmed, five-round median router measurements, including optional routes against equivalent explicit routes. Results depend on the machine and Bun version and are not a performance guarantee.

Proxy trust and client IP

By default, forwarded headers are ignored. Configure trustProxy with the exact proxy IPs or CIDR ranges that connect directly to the app. Barq walks X-Forwarded-For from the nearest hop and stops at the first untrusted address. trustProxy: true trusts every hop and is unsafe when clients can reach the app directly; prefer explicit ranges.

Keep the global idleTimeout enabled for ordinary traffic. A value of 0 disables it; use ctx.disableTimeout() only for a request that needs a long-lived stream.

app.cluster(port) starts one Bun worker per logical CPU on Linux and binds workers with reusePort; await app.stop() terminates the workers. Windows and macOS use a single-process listener because Bun's reusePort option is ignored there. Clustering requires a fixed non-zero port and the application entry file must call app.cluster() in each worker.

WebSocket deployments can bound inbound messages with websocket.maxPayloadLength and queued output with websocket.backpressureLimit. Set limits based on the application protocol; Bun's defaults permit messages and queued data up to 16 MiB per connection.

Development

bun install
bun run check
bun run typecheck
bun run typecheck:tests
bun test
bun run build
bun run bench
bun run bench:middleware
bun run bench:runtime

dist/ is generated by the build. Tests use Bun's test runner. The package is MIT licensed; see LICENSE.