@momics/iroh-http-node
v0.5.2
Published
Node.js native addon for iroh-http (napi-rs)
Readme
@momics/iroh-http-node
Pre-v1.0. APIs may change between minor releases.
Node.js adapter for iroh-http. Native addon via napi-rs. No child processes, no WASM.
Install
npm install @momics/iroh-http-nodePre-built binaries are published for macOS (x64, ARM), Linux glibc (x64, ARM), and Windows (x64). Other platforms need a source build:
npx napi build --platform --releaseQuick start
import { createNode } from "@momics/iroh-http-node";
const node = await createNode();
console.log("Node ID:", node.publicKey.toString());
node.serve({}, (req) => {
if (req.headers.get("Peer-Id") !== ALLOWED_PEER) {
return new Response("Forbidden", { status: 403 });
}
return new Response("hello");
});
const res = await node.fetch("httpi://<peer-public-key>/");
console.log(await res.text());
await node.close();Full API
The API is identical across Node.js, Deno, and Tauri: HTTP fetch/serve, QUIC sessions, mDNS discovery, and Ed25519 crypto. See the API overview for the complete reference.
Node.js specifics
- Standalone crypto functions (
generateSecretKey,secretKeySign,publicKeyVerify) are synchronous. They run in Rust on the calling thread without a Tokio round-trip. - The class API on a live node (
node.secretKey.sign(),node.publicKey.verify()) is async. - Serve callbacks run on the Node.js event loop via napi-rs
ThreadsafeFunction.
Other runtimes
| Runtime | Package |
| -------- | ---------------------------------------------------------------------------------- |
| Deno | @momics/iroh-http-deno |
| Tauri v2 | @momics/iroh-http-tauri |
License
MIT OR Apache-2.0
