Node.js Runtime

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

Basic Usage

import { serve } from "sevo";
import { NodeRuntimeAdapter } from "sevo/node";

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

Runtime-Specific Server Options

Use ServerOptions.node to pass native Node listener and server options through NodeRuntimeAdapter.

NodeServerOptions combines:

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

That means you can configure both listener options and runtime-specific Node server options on the node field:

serve({
  adapter: new NodeRuntimeAdapter(),
  node: {
    requestTimeout: 30_000,
    keepAliveTimeout: 5_000,
  },
  fetch() {
    return new Response("Hello from Node");
  },
});

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 node.http2: true is set, it creates a secure HTTP/2 server instead.

import { serve } from "sevo";
import { NodeRuntimeAdapter } from "sevo/node";

serve({
  adapter: new NodeRuntimeAdapter(),
  protocol: "https",
  tls: {
    cert: "./certs/dev-cert.pem",
    key: "./certs/dev-key.pem",
  },
  node: { http2: true },
  fetch() {
    return new Response("secure");
  },
});

HTTP/2 still 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 sevo --entry ./server.tsx --import jiti/register