I wanted to use Typst from Node.js the way I use any other dependency: pinned in package.json, called without shell strings, and not surprised by a new Typst release. So I ended up building two npm packages.
@flukxr/typst-cli
The official Typst binaries as an npm dependency. The exact Typst version is pinned in package.json like any other dependency, and npm installs only the binary for your platform. No postinstall scripts, nothing downloaded at runtime. Every stable release since 0.1.0 is available.
npm install @flukxr/typst-cli@typst-0.15.1 @flukxr/typst-api
@flukxr/typst-api
A typed Node.js API over the native CLI.
import { compile, pdf, query, jsonInput, source } from "@flukxr/typst-api";
// File to file, like `typst compile`
await compile("main.typ", "out.pdf");
// Data in, PDF Buffer out (read it in Typst with `json(bytes(sys.inputs.data))`)
const invoice = await pdf("invoice.typ", {
inputs: { data: jsonInput({ id: 42, total: 100 }) },
});
// Markup from memory
const hello = await pdf(source("= Hello"));
// Query the document
const { elements } = await query("main.typ", "heading");
What it does:
compile,query,watch,eval,fontsand more, with typed results- typed errors with raw stderr preserved and optional structured diagnostics
- no shell: arguments are passed directly, so odd paths are safe
- version-aware: known options are validated against your exact Typst version before the compiler runs (0.15.0 and 0.15.1 are different checkpoints)
- works with
@flukxr/typst-cli,TYPST_PATHor Typst onPATH extraArgsand a rawrun(args)for flags newer than the package- zero runtime dependencies, published with npm provenance
The fun part: tracking Typst versions
The flag table isn’t written by hand. I snapshot typst --help for every stable release since 0.1.0 and use those snapshots to determine when each flag and value first appeared. Help output is only treated as evidence, though: --make-deps vanished from the help in 0.14.0 but still works, so removals are confirmed on real binaries. A nightly CI job watches for new Typst releases and prepares the compatibility updates for review.
The snapshot corpus is public too: flukxr/typst-snapshots on GitHub.
Limitations
- Node.js only: it drives the native CLI
- every call starts the Typst CLI, which is fine for documents, scripts and CI, but not built for thousands of compilations per second
Both packages are community-maintained side projects, not part of Typst itself.
Feedback is very welcome, especially if you call Typst from Node in some other way.