Node.js Runtime

NodeRuntimeAdapter bridges Web Request/Response handling to Node's HTTP server APIs.

Basic Usage

import { serve } from "@hornjs/fest";
import { NodeRuntimeAdapter } from "@hornjs/fest/node";

serve({
  adapter: new NodeRuntimeAdapter(),
  fetch() {
    return new Response("Hello from Node");
  },
});

Constructor Options

new NodeRuntimeAdapter(options) accepts NodeServerOptions, which combines:

  • http.ServerOptions
  • https.ServerOptions
  • http2.ServerOptions
  • net.ListenOptions
  • http2?: boolean

That means you can pass both listener options and runtime-specific Node server options directly to the adapter constructor.

Commonly Used Options

  • http2: switch the adapter to node:http2.createSecureServer()
  • requestTimeout: configure the HTTP server request timeout
  • keepAliveTimeout: configure keep-alive timeout
  • maxHeaderSize: limit accepted header size
  • allowHTTP1: relevant when HTTP/2 is enabled and you want HTTP/1 fallback
  • ipv6Only, backlog, exclusive, signal: inherited from net.ListenOptions

Official References

What the Adapter Does

For each incoming request, the adapter:

receives IncomingMessage and ServerResponse

converts the request into a standard Request

runs it through server.fetch()

writes the resulting Response back to Node's response object

HTTPS and HTTP/2

If TLS options are present, the adapter creates an HTTPS server by default. When http2: true is passed to NodeRuntimeAdapter, it creates a secure HTTP/2 server instead.

import { NodeRuntimeAdapter } from "@hornjs/fest/node";

const adapter = new NodeRuntimeAdapter({ http2: true });

HTTP/2 requires TLS configuration.

Close Behavior

server.close(true) asks the Node adapter to close active HTTP connections when the underlying server supports closeAllConnections().

TypeScript Entrypoints

For local examples, Node.js can run .ts files with:

node --experimental-strip-types server.ts

If you need JSX or TSX, use the CLI with a loader:

JITI_JSX=1 fest --entry ./server.tsx --import jiti/register