1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Use a module in Node
Node 25 or later.
```bash run=network
mkdir use-node && cd use-node && npm init -y > /dev/null && npm i @publicdomainrelay/atlibs@0.5.0 > /dev/null
```
Save as `main.mjs`, then `node main.mjs`:
```js run=network
import { loadModule, runModule } from "@publicdomainrelay/atlibs/run-module/index.js";
import { createNodeContext, hostCall } from "@publicdomainrelay/atlibs/server/index.js";
const did = "did:plc:ocnuqjlzgohypj3zoznermms";
const ctx = createNodeContext({ id: "demo", stateDir: ".state" });
const hello = await loadModule(ctx, "bobvmbuilder.bsky.social/hello");
const { result, error } = await runModule(ctx, hello, "count", { did, collection: "com.fedfork.exec.wasm.module" }, hostCall({ ctx }));
console.log(JSON.stringify(error ?? result));
```
```output
{"collection":"com.fedfork.exec.wasm.module","records":…}
```
A local build instead of a published one:
`localModule(new URL("hello.wasm", import.meta.url), new URL("hello.json", import.meta.url), fileFetch)`
(`fileFetch` from `server/index.js`; `atlibs add` writes both files to `modules/`).
Servers, sign-in, Hono: [Node servers](../server/node.md), `examples/node-hono`.
Previous: [Page](page.md) | Next: [CLI](cli.md)