Node.js and Electron N-API Version Checker

0.2.1 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import { fromNodeVersion, fromElectronVersion } from 'node-api-version';

// Determine the Node-API version for specific Node.js releases
const napiNode9 = fromNodeVersion('9.0.0');
console.log(`Node 9.0.0 N-API version: ${napiNode9 || 'N/A'}`);

const napiNode12 = fromNodeVersion('12.13.0');
console.log(`Node 12.13.0 N-API version: ${napiNode12 || 'N/A'}`);

const napiNode16 = fromNodeVersion('16.0.0');
console.log(`Node 16.0.0 N-API version: ${napiNode16 || 'N/A'}`);

// Determine the Node-API version for specific Electron releases
const napiElectron2 = fromElectronVersion('2.0.0');
console.log(`Electron 2.0.0 N-API version: ${napiElectron2 || 'N/A'}`);

const napiElectron13 = fromElectronVersion('13.0.0');
console.log(`Electron 13.0.0 N-API version: ${napiElectron13 || 'N/A'}`);

const napiElectron15Nightly = fromElectronVersion('15.0.0-nightly.20210629');
console.log(`Electron 15.0.0-nightly N-API version: ${napiElectron15Nightly || 'N/A'}`);

// Example of an unsupported version
const napiUnknown = fromNodeVersion('0.10.0');
console.log(`Node 0.10.0 N-API version: ${napiUnknown || 'N/A'}`);

view raw JSON →