assert-node-version is a lightweight utility designed to programmatically verify the current Node.js runtime version against a specified requirement, typically defined in a project's `package.json` file under the `engines.node` field or within a `.nvmrc` file. The current stable version is 1.0.3. It operates synchronously and will throw an error if the installed Node.js version does not meet the specified criteria, effectively halting execution early in scenarios where version compatibility is critical. This package offers a simple, direct API with minimal configuration, differentiating itself by its singular focus on version assertion and its reliance on common project configuration files rather than complex custom setup. Its release cadence appears to be stable and infrequent, reflecting its mature and focused functionality.
npm install assert-node-versionVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `assert-node-version` by creating temporary project configurations (`package.json` and `.nvmrc`) to simulate both successful version checks and cases where the assertion fails, leading to an error being thrown.
Wrap calls to `assert-node-version` in a `try...catch` block if you need to gracefully handle version mismatches rather than letting the process exit. Example: `try { require('assert-node-version')(); } catch (e) { console.error('Version mismatch:', e.message); process.exit(1); }`Verify the contents of `package.json` (specifically `engines.node`) and `.nvmrc` files in the directory where the assertion is run. Avoid conflicting specifications between these two files for clarity.
Always ensure the Node.js process's current working directory (`process.cwd()`) is the root of the project you intend to check, or explicitly pass the correct project directory path to the function, e.g., `require('assert-node-version')(path.join(__dirname, '../'))`.Update your Node.js installation to a version that satisfies the requirement (e.g., using `nvm install <version>` and `nvm use <version>`), or adjust the version requirement in your `package.json` or `.nvmrc` file to match your current Node.js version (if appropriate).
Call the required module directly as a function: `require('assert-node-version')(directory)` instead of `const assert = require('assert-node-version').assert;` or similar.No dependency data recorded yet.