Node-API and native ABI
Prerequisite: node-package-release-review. Objective: Compare ABI and runtime versions. Tested locally on Node.js 22.16.0 Linux. Each example is independent. Use a fresh disposable working directory, save as main.mjs, then run node main.mjs. The harness uses a five-second timeout and synthetic environment. These are static code blocks, not ByteMind interactive execution.
How it works
An addon compiled using only the supported Node-API surface can often be reused across Node releases supporting its requested Node-API version. That promise does not cover arbitrary V8 C++ APIs or external libraries; OS, CPU architecture, libc and other ABI constraints still matter. process.versions.napi reports the runtime's supported Node-API version; process.versions.modules is the traditional native module ABI number. They are different identifiers. Native code can violate memory safety and runs with process privileges. A typical build uses a reviewed C/C++ toolchain and node-gyp or equivalent; no native compilation or addon loading is authorized in this lab.
Inspect the runtime ABI identifiers
import assert from 'node:assert/strict';for(const key of ['napi','modules'])assert.match(process.versions[key],/^\d+$/);console.log('both ABI identifiers present');Expected output:
both ABI identifiers presentThe actual values are runtime-dependent and intentionally not hardcoded.
Model a binary compatibility preflight
function eligible(runtime,addon){return runtime.os===addon.os&&runtime.arch===addon.arch&&runtime.napi>=addon.napi;}const r={os:'linux',arch:'x64',napi:10};for(const a of [{os:'linux',arch:'x64',napi:8},{os:'linux',arch:'arm64',napi:8},{os:'linux',arch:'x64',napi:11}])console.log(eligible(r,a));Expected output:
truefalsefalseThis model checks three necessary conditions, not actual compatibility or trust; libc and linked libraries are omitted.
Common mistakes
Never infer that a matching Node-API version makes arbitrary native code safe, or that a Linux binary runs on every platform.
Practice
List the build, platform, dependency and provenance checks required before using a reviewed addon.
Reference candidate: node-node-api-and-native-abi-lookup (route unverified). Documentation: https://nodejs.org/download/release/v22.16.0/docs/api/n-api.html (opened); https://nodejs.org/download/release/v22.16.0/docs/api/process.html (opened).
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Node-API and native ABI — knowledge check
Apply the lesson to a fresh scenario and explain the evidence boundary.
What does ABI compatibility concern?
A runtime supports Node-API 10; an addon needs 11. What follows?
Can matching Node-API versions prove an addon is safe?