Run an @askrjs/server application on Node.js. The adapter translates Node HTTP messages at the
boundary while the application continues to use Web Request and Response objects.
npm install @askrjs/server @askrjs/nodeimport { createServer } from "node:http";
import { createServerApp, json } from "@askrjs/server";
import { createNodeHandler } from "@askrjs/node";
const app = createServerApp({
routes: [{ path: "/health", handler: () => json({ status: "ok" }) }],
});
createServer(createNodeHandler(app, { baseUrl: "http://localhost:3000" })).listen(3000);createNodeHandler also works as Connect middleware because it accepts an optional next
callback. It preserves streaming bodies, repeated Set-Cookie headers, aborts, backpressure,
status text, and HEAD responses.
import { listen } from "@askrjs/node";
const server = await listen(app, {
port: 3000,
requestTimeout: 120_000,
headersTimeout: 60_000,
keepAliveTimeout: 5_000,
});
server.close();Pass an AbortSignal to integrate shutdown with your process lifecycle.
Enable the built-in ws transport with websocket: true. It defaults to a
1 MiB maximum message payload with compression disabled; pass
websocket: { maxPayload, perMessageDeflate } to override those settings.
router.ws("/echo", (socket) => {
socket.onMessage((message) => socket.send(message));
});
const server = await listen(createServerApp({ router }), { websocket: true });Route matching, authentication, and middleware complete before the handshake. Rejected upgrades preserve the application response, and shutdown closes active sockets.
import { serve } from "@askrjs/node";
const running = await serve(app, {
port: 3000,
assets: { root: "./dist/client" },
});
await running.close();serve handles static assets and closes both the HTTP server and the application during shutdown.
import { connectMcpStdio } from "@askrjs/node/mcp";
const connection = connectMcpStdio(mcp, { dependencies });
await connection.closed;Protocol messages use stdin/stdout; diagnostics remain isolated on stderr. Authentication may be provided directly or resolved from the process environment for each message.