The `node-api-version` package provides a programmatic way to determine the maximum Node-API (N-API) version supported by specific Node.js or Electron runtime versions. This utility is critical for developers working with native Node.js addons, enabling them to ensure compatibility and manage prebuilt binaries efficiently across different runtime environments. By querying N-API support directly, it helps avoid ABI mismatches and streamlines the native module compilation and distribution process. The current stable version is 0.2.1, indicating a stable but early-stage utility, likely with an infrequent release cadence tied to updates in Node.js and Electron. Its primary differentiator is offering a simple, automated lookup without requiring manual maintenance of N-API version tables.
npm install node-api-versionVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `fromNodeVersion` and `fromElectronVersion` to query Node-API compatibility for various runtime versions, showing results for both supported and unsupported inputs.
Implement explicit checks for `undefined` results: `const napiVersion = fromNodeVersion('...'); if (napiVersion === undefined) { /* handle unsupported */ }`Pin to exact versions for production environments (`"node-api-version": "0.2.1"`) and manually verify functionality after any upgrade, even for minor version bumps.
For pure Node.js ESM projects, ensure your `package.json` has `"type": "module"` and consider using bundlers or transpilers for consistency. Otherwise, stick to `require()` for CommonJS contexts.
Use `const { fromNodeVersion } = require('node-api-version');` for CommonJS.Verify the version string for typos and ensure it's a version that is expected to have N-API support. Handle the `undefined` return explicitly in your code.
Use named imports: `import { fromNodeVersion, fromElectronVersion } from 'node-api-version';`No dependency data recorded yet.