Custom Node.js binary
By default pkg downloads a pre-compiled, patched Node.js binary from pkg-fetch and uses it as the base for every executable it creates. For most projects this is exactly what you want.
If you need a custom base binary — for an architecture not covered by pkg-fetch, a build with specific V8 flags, or a Node.js you've already patched for Windows metadata or corporate compliance — set PKG_NODE_PATH to point at it:
bash
PKG_NODE_PATH=/path/to/node pkg app.jspkg will use that binary as the base instead of fetching one.
When to use a custom binary
- Unsupported architectures —
pkg-fetchcovers Linux / macOS / Windows on x64 + arm64. For anything else (RISC-V, armv6, BSD), compile Node.js yourself or use apkg-binariesbuild. - Pre-embedded metadata — on Windows, you can compile a Node.js binary that already has your product name, icon, and version baked in. Then
pkg-ing your JS on top preserves it. See Windows metadata for an alternative post-processing approach. - Security policy — enterprises that pin Node.js to a specific internal build can feed it into
pkg. - Debug builds — a debug-enabled Node.js lets you attach a debugger to the packaged app in development.
Caveats
- The binary must be a compatible Node.js version —
pkgstill injects its bootstrap prelude and payload, and depends on specific symbol offsets. Use a version supported bypkg-fetchunless you know what you're doing. PKG_NODE_PATHaffects a single target. Multi-target builds still fetch the other platforms frompkg-fetchunless you set it per-run.- SEA mode uses stock Node.js by its own mechanism and does not honour
PKG_NODE_PATHin the same way. For SEA, useprocess.execPathof the Node.js you want directly.
