Quick start

The fastest path to a working addon is the scaffolder. It picks up your package manager, writes a starter project, installs everything, and produces a built binary you can import from Node.

Prerequisites

  • Zig 0.16.0.
  • Node.js >=20.19.0 to run napikit, plus a package manager (npm, pnpm, yarn, or bun).
  • If you choose Bun, use Bun 1.3.14, matching the generated workflow baseline.

Scaffold

npx napikit@latest new my-addon

The CLI prompts for any missing details, then:

  • Writes build.zig, build.zig.zon, and package.json.
  • Drops a starter src/lib.zig with two example functions.
  • Installs napikit from npm and fetches the Zig dependency.
  • Adds a .github/workflows/publish.yml ready for trusted publishing.
  • Runs an initial build so the binary is available immediately.

Try it

cd my-addon
node test.mjs
add(2, 3) = 5
greet('world') = Hello, world!

That's it. You have a working native Node.js addon written in Zig.

What the starter contains

// src/lib.zig
const std = @import("std");
const napi = @import("napi");

comptime { napi.module(@This()); }

pub fn add(a: i32, b: i32) i32 {
    return a + b;
}

pub fn greet(env: napi.Env, name: []const u8) ![]const u8 {
    return std.fmt.allocPrint(env.allocator(), "Hello, {s}!", .{name});
}
// test.mjs
import addon from "./my-addon.js";

console.log("add(2, 3) =", addon.add(2, 3));
console.log("greet('world') =", addon.greet("world"));

The development loop

Every iteration is the same two-step:

# edit src/lib.zig, then:
napikit build
node test.mjs

napikit build compiles for the current host. When you are ready to ship, napikit build --release cross-compiles every platform at once. See Cross-compiling.

Next steps