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

@openknot-ts/knot-http-node

v0.0.6-preview

Published

Node HTTP server lifecycle and draining for OpenKnot applications.

Readme

@openknot-ts/knot-http-node

A native node:http host. It listens, drains admitted requests on shutdown and serves the (request, response) handler the application selects. Routing, body parsing and errors belong to the handler; the host has no tRPC, Express, Fastify or WebSocket dependency.

Usage

import { http } from "@openknot-ts/knot-http-node";
import { trpcHttp } from "@openknot-ts/trpc-knot-server-handler";
import { defineApplication } from "@openknot-ts/wire";

export const application = defineApplication({
  modules: [transport, http, trpcHttp],
});

http supplies the host; a protocol module such as trpcHttp implements its handler contract. Missing handlers fail at runApplication(), before any resource is acquired.

API

| Export | Description | | --- | --- | | http | Ready module listing httpServer. | | httpServer | The default host resource, configured by httpConfig. Resolves to { native, url, listening }. | | nodeHttpServer({ handler, requirements?, options?, listen? }) | Declares another host: independent handlers, native options or several servers. | | httpConfig | The default host's environment configuration. | | httpHandler | Contract for the final RequestListener; implement it with unit({ provides: httpHandler, factory }). | | httpMiddleware, HttpMiddleware | Collection contract for native (request, response, next) middleware. |

httpHandler, httpMiddleware and HttpMiddleware are also exported from @openknot-ts/knot-http-node/handler, which protocols import without loading the host.

Configuration

| Variable | Default | Meaning | | --- | --- | --- | | PORT | 3000 | TCP port; 0 picks a free port. | | HTTP_HOST | 127.0.0.1 | Bind address; IPv6 is supported. | | HTTP_REQUEST_TIMEOUT_MS | native (300000) | Time to receive the whole request; 0 disables it. | | HTTP_HEADERS_TIMEOUT_MS | native | Time to receive headers; 0 disables it. | | HTTP_KEEP_ALIVE_TIMEOUT_MS | native (5000) | Idle time after a response before the connection closes. | | HTTP_KEEP_ALIVE_TIMEOUT_BUFFER_MS | native (1000) | Extra socket time beyond the advertised keep-alive. | | HTTP_SOCKET_TIMEOUT_MS | native (0) | Socket inactivity timeout; disabled so long responses and SSE stay open. | | HTTP_MAX_HEADER_SIZE | native (16384) | Maximum header bytes. | | HTTP_MAX_HEADERS_COUNT | native | Maximum header count; 0 removes the limit. | | HTTP_MAX_REQUESTS_PER_SOCKET | native (0) | Requests per keep-alive connection; 0 is unlimited. |

Values are validated at startup. Unset tuning variables keep Node's defaults. Precedence: environment, then options, then Node defaults.

env HTTP_KEEP_ALIVE_TIMEOUT_MS=15000 HTTP_REQUEST_TIMEOUT_MS=120000 pnpm example:quickstart

Custom hosts

options takes any Node ServerOptions, as an object or a callback over requirements. listen replaces the default PORT/HTTP_HOST configuration entirely: httpConfig is not read and the callback returns native ListenOptions (ports, Unix socket path, backlog, signals).

const settings = config({
  API_PORT: z.coerce.number().int().min(0).max(65_535).default(8080),
  API_HOST: z.string().default("127.0.0.1"),
});

const server = nodeHttpServer({
  handler: httpHandler,
  requirements: { settings },
  options: { highWaterMark: 64 * 1024 },
  listen: ({ settings }) => ({ port: settings.API_PORT, host: settings.API_HOST }),
});

Select it with providePlugs([server]) instead of http. Several hosts can run side by side with their own settings. httpServer.native is the real http.Server for native APIs and events.

Middleware

Middleware units that provide httpMiddleware run in module order before the handler. Each receives the native (request, response, next), may answer or return next(), and keeps the server as this. A middleware reached only as a dependency does not join the pipeline. @openknot-ts/knot-health uses this contract: select its healthHttp module to serve /livez, /readyz and /health.

A handler or middleware that throws fails only its own request: the host hands the failure to unattendedFailures, which logs it and reports it when a reporter is bound, and answers 500, or closes the connection if headers were already sent. A handler answers the failures of the executions it invokes, as trpcHttp and restRouter do: Flow has already logged and reported them, so one it lets through is logged and reported twice.

Lifecycle

  • The host is a Wire resource. It listens before startup tasks run, after Flow's listeners when it serves Flow exposures.
  • A failed bind, or a cancelled startup, rejects runApplication() and releases the socket. url reports the bound address and port.
  • On stop, admitted responses get Connection: close and finish; idle connections close at once; new requests on open sockets get 503. Nothing truncates admitted work.
  • WebSocket servers can attach to httpServer.native; their adapter closes their connections. Flow topic and broadcast streams end when the application starts stopping.
  • The host serves HTTP/1.1. HTTPS and HTTP/2 need their native servers, such as @openknot-ts/fastify-server.

Examples and tests