Skip to content

Commit 6a84ed7

Browse files
committed
docs(node): use ESM import in the usage example
The napi-rs addon is a CommonJS package, but ESM `import` resolves its named exports via Node's interop, so the example now leads with `import` and notes that CJS `require` works too.
1 parent 1e0d658 commit 6a84ed7

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎bindings/node/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The `napi build` command (from `@napi-rs/cli`) compiles the Rust crate and write
1717
napi-rs automatically converts Rust `snake_case` function names to JS `camelCase` (`build_graph` → `buildGraph`, `language_of` → `languageOf`). TypeScript types are generated as `index.d.ts`.
1818

1919
```js
20-
const { extract, buildGraph, languageOf } = require("@nodedb-lab/code2graph");
20+
import { extract, buildGraph, languageOf } from "@nodedb-lab/code2graph";
2121

2222
const facts = extract("src/lib.rs", "pub fn hello() {}");
2323
const graph = buildGraph([facts], "name");
@@ -27,4 +27,6 @@ console.log(languageOf("src/main.go")); // "go"
2727
console.log(languageOf("unknown.xyz")); // null
2828
```
2929

30+
The addon is a CommonJS package, so CJS `require("@nodedb-lab/code2graph")` works too — ESM `import` resolves via Node's interop.
31+
3032
The `tier` argument to `buildGraph` is `"name"` (default, Tier A — fast, recall-first, `NameOnly` confidence) or `"scope"` (Tier B — scope-graph path resolution, `Scoped`/`Exact` confidence).

0 commit comments

Comments
 (0)