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

@streetjs/context

v1.1.0

Published

StreetJS request/response context: a strict per-request StreetContext over Node's http req/res with JSON/text/HTML/send helpers, header and secure-by-default cookie handling, params/query/body/state, and a single-write guard.

Readme

@streetjs/context

The StreetJS request/response context: createContext(req, res, path, query) builds a strict StreetContext over Node's http request/response with ergonomic responders, a single-write guard, header access, and secure-by-default cookies. ESM, strict-TypeScript.

This is the standalone home of the context that also backs the streetjs framework's HTTP layer. The framework re-exports this package, so there is a single source of truth.

Install

npm install @streetjs/context

Usage

import { createContext } from '@streetjs/context';
import { createServer } from 'node:http';

createServer((req, res) => {
  const url = new URL(req.url ?? '/', 'http://localhost');
  const query = Object.fromEntries(url.searchParams);
  const ctx = createContext(req, res, url.pathname, query);

  if (ctx.path === '/health') return ctx.json({ status: 'ok' });
  ctx.text('not found', 404);
}).listen(3000);

The context

StreetContext exposes the raw req/res plus:

  • Request: path, method (uppercased), query, headers (lowercased keys, array values joined), body, rawBody, files, startTime.
  • Mutable slots that middleware fills in: params, body, state, user, files.
  • Responders: json(data, status?), text(data, status?), html(data, status?), send(status). Each sets appropriate content headers (nosniff on JSON/HTML) and is guarded by sent — the first responder wins, later calls are no-ops, preventing double-send crashes.
  • Headers & cookies: setHeader(name, value), cookie(name) (reads and URL-decodes a request cookie), setCookie(name, value, options?).

Cookies

setCookie and the exported pure serializeCookie(name, value, options?) apply secure-by-default flags:

| Option | Default | | ------ | ------- | | httpOnly | true (emit HttpOnly) | | secure | true when NODE_ENV === 'production', else omitted | | sameSite | 'Lax' |

Pass explicit values to override (httpOnly: false, secure: true/false, a different sameSite). maxAge, path, and domain are appended when set. Multiple setCookie calls append multiple Set-Cookie values rather than overwriting.

serializeCookie('sid', 'abc', { maxAge: 3600, path: '/' });
// "sid=abc; HttpOnly; SameSite=Lax; Max-Age=3600; Path=/"   (outside production)

Example

A complete runnable example lives in src/examples/integration.ts:

npm run example -w packages/context

License

MIT — see LICENSE.