Registry / devops / node-exec-path

node-exec-path

JSON →
library1.2.1jsnpmunverified

The `node-exec-path` package provides utilities for locating Node.js executable paths on a system and verifying if a particular Node.js installation satisfies a given semantic version range. It offers both synchronous (`satisfiesSemverSync`) and likely asynchronous (`satisfiesSemver`) methods to perform these checks. The current stable version is 1.2.1, though recent public release notes primarily show minor dependency upgrades, suggesting a focus on stability and maintenance rather than frequent new features. Its key differentiator is the direct integration of `semver` logic to programmatically identify suitable Node.js environments, which is crucial for applications that need to ensure compatibility with specific Node.js versions, especially in environments utilizing tools like `nvm` or `volta` where multiple Node.js installations coexist. This package abstracts away the complexities of searching `PATH` and parsing version strings.

npm install node-exec-path
INSTALL
IMPORT
SIG · NODE-EXEC-PATH
N
node-exec-path
devopsjavascriptv1.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

satisfiesSemverSync
import { satisfiesSemverSync } from 'node-exec-path';
const { satisfiesSemverSync } = require('node-exec-path');
The package ships TypeScript types and is designed for modern Node.js environments, favoring ESM imports. While CJS might work in some contexts, ESM is the recommended approach.
satisfiesSemver
import { satisfiesSemver } from 'node-exec-path';
const satisfiesSemver = require('node-exec-path').satisfiesSemver;
Assumed asynchronous counterpart to 'satisfiesSemverSync', following common Node.js API patterns. Always prefer named imports for clarity.

Demonstrates how to synchronously find a Node.js executable path that satisfies a specified semantic version range, returning the absolute path or null.

import { satisfiesSemverSync } from "node-exec-path"; // Find a Node.js executable path that satisfies Node.js version >= 18.0 const execPath = satisfiesSemverSync(">=18.0"); if (execPath) { console.log(`Found compatible Node.js at: ${execPath}`); // You can then use child_process.execFile to run scripts with this Node.js version // import { execFile } from 'node:child_process'; // execFile(execPath, ['-v'], (error, stdout, stderr) => { // if (error) { console.error(error); return; } // console.log(`Version found: ${stdout.trim()}`); // }); } else { console.log("No Node.js executable found satisfying '>=18.0'."); } // Example with a different range const node20Path = satisfiesSemverSync("~20.x"); if (node20Path) { console.log(`Found Node.js ~20.x at: ${node20Path}`); }
Debug
Known issues
gotchaWhen multiple Node.js installations are present (e.g., via NVM, Volta, or system-wide installs), `node-exec-path` will return the first compatible executable it finds in the system's PATH. This might not always be the 'active' or desired version if not carefully managed by the user's environment setup.
fix
Ensure your system's PATH environment variable is ordered correctly or explicitly specify the desired Node.js version management tool's path before using `node-exec-path` if you need specific precedence.
affects: >=1.0.0
gotchaThe synchronous `satisfiesSemverSync` method can be blocking for I/O operations, especially if the system's PATH contains many directories or network drives, potentially impacting application responsiveness. Consider using asynchronous alternatives if available for performance-critical scenarios.
fix
If high performance is critical or for long-running processes, investigate if an asynchronous equivalent (like `satisfiesSemver`) is exposed by the library and use it to avoid blocking the event loop.
affects: >=1.0.0
gotchaPath strings containing spaces (e.g., 'C:\Program Files\Nodejs\node.exe') can be problematic when passed directly to `child_process.exec` without proper quoting or when relying on shell interpretation. While `node-exec-path` returns the path, users consuming it in `child_process` should be aware.
fix
When using the returned executable path with Node's `child_process` module, prefer `child_process.execFile` (which accepts the executable and arguments separately) over `child_process.exec` for robustness, or ensure proper quoting of paths with spaces if using `exec` with a shell.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'node-exec-path'
The 'node-exec-path' package is not installed or not accessible in the current project's `node_modules`.
fix
Run `npm install node-exec-path` or `yarn add node-exec-path` to install the package.
TypeError: (0, node_exec_path_1.satisfiesSemverSync) is not a function
This usually indicates an attempt to use a CommonJS `require()` statement or an incorrect default import for a package designed for named ESM imports.
fix
Ensure you are using `import { satisfiesSemverSync } from 'node-exec-path';` for ESM contexts. If in a CJS file, ensure `package.json` specifies `"type": "module"` or the library provides a CJS entry point.
Invalid SemVer range: 'invalid-version-string'
The input string provided to `satisfiesSemverSync` (or other semver-related functions) does not conform to the semantic versioning specification.
fix
Provide a valid semantic version range string, for example, '>=18.0.0', '^16.x', '14.17.0 - 16.x', or similar. Refer to the `semver` documentation for valid range syntax.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
semverrequiredUsed for parsing and comparing Node.js versions to satisfy specified ranges.
Agent activity
2 hits · last 30 days
node
2
Resources
node-exec-path — npm install node-exec-path · libregistry