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.ServerOptionshttps.ServerOptionshttp2.ServerOptionsnet.ListenOptionshttp2?: 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 tonode:http2.createSecureServer()requestTimeout: configure the HTTP server request timeoutkeepAliveTimeout: configure keep-alive timeoutmaxHeaderSize: limit accepted header sizeallowHTTP1: relevant when HTTP/2 is enabled and you want HTTP/1 fallbackipv6Only,backlog,exclusive,signal: inherited fromnet.ListenOptions
Official References
- Node HTTP server options: https://nodejs.org/api/http.html#httpcreateserveroptions-requestlistener
- Node HTTPS server options: https://nodejs.org/api/https.html#httpscreateserveroptions-requestlistener
- Node listen options: https://nodejs.org/api/net.html#serverlistenoptions-callback
- Node HTTP/2 secure server options: https://nodejs.org/api/http2.html#http2createsecureserveroptions-onrequesthandler
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