@askrjs/node 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +69 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # @askrjs/node
2
+
3
+ [![CI](https://github.com/askrjs/askr-node/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/askrjs/askr-node/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/%40askrjs%2Fnode.svg)](https://www.npmjs.com/package/@askrjs/node)
5
+
6
+ Run an `@askrjs/server` application on Node.js. The adapter translates Node HTTP messages at the
7
+ boundary while the application continues to use Web `Request` and `Response` objects.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install @askrjs/server @askrjs/node
13
+ ```
14
+
15
+ ## Create a Node handler
16
+
17
+ ```ts
18
+ import { createServer } from "node:http";
19
+ import { createServerApp, json } from "@askrjs/server";
20
+ import { createNodeHandler } from "@askrjs/node";
21
+
22
+ const app = createServerApp({
23
+ routes: [{ path: "/health", handler: () => json({ status: "ok" }) }],
24
+ });
25
+
26
+ createServer(createNodeHandler(app)).listen(3000);
27
+ ```
28
+
29
+ `createNodeHandler` also works as Connect middleware because it accepts an optional `next`
30
+ callback. It preserves streaming bodies, repeated `Set-Cookie` headers, aborts, backpressure,
31
+ status text, and HEAD responses.
32
+
33
+ ## Listen directly
34
+
35
+ ```ts
36
+ import { listen } from "@askrjs/node";
37
+
38
+ const server = await listen(app, { port: 3000 });
39
+ server.close();
40
+ ```
41
+
42
+ Pass an `AbortSignal` to integrate shutdown with your process lifecycle.
43
+
44
+ ## Serve a production application
45
+
46
+ ```ts
47
+ import { serve } from "@askrjs/node";
48
+
49
+ const running = await serve(app, {
50
+ port: 3000,
51
+ assets: { root: "./dist/client" },
52
+ });
53
+
54
+ await running.close();
55
+ ```
56
+
57
+ `serve` handles static assets and closes both the HTTP server and the application during shutdown.
58
+
59
+ ## MCP over stdio
60
+
61
+ ```ts
62
+ import { connectMcpStdio } from "@askrjs/node/mcp";
63
+
64
+ const connection = connectMcpStdio(mcp, { dependencies });
65
+ await connection.closed;
66
+ ```
67
+
68
+ Protocol messages use stdin/stdout; diagnostics remain isolated on stderr. Authentication may be
69
+ provided directly or resolved from the process environment for each message.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askrjs/node",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Node http adapter for @askrjs/server",
5
5
  "keywords": [
6
6
  "askr",