Local Node.js Binary Installer
This package, `node`, facilitates the management and usage of specific Node.js runtime versions as a local project dependency. By installing it, a `node` binary is placed within `node_modules/.bin`, which npm automatically adds to the `PATH` when running scripts, ensuring that local project scripts consistently execute with the intended Node.js version, distinct from the system's globally installed Node.js. The current stable version provided through `node@lts` aligns with the latest Node.js LTS release, currently `24.15.0` as of its recent publication. The package generally follows Node.js's traditional release cadence, with major versions being branched every six months and even-numbered versions typically becoming LTS. This approach provides a robust alternative to global version managers (like `nvm` or `volta`) for project-specific environments, simplifying CI/CD setups and team development by treating the runtime as a regular `package.json` dependency. Releases track Node.js major versions, offering flexibility to target specific versions (e.g., `node@18`, `node@20`, `node@lts`) through `npm i` or `npx` commands.
Common errors
-
Error: command not found: node
cause Attempting to run 'node script.js' directly in the shell after local installation without using 'npm run' or 'npx'.fixUse 'npm run <script-name>' if the script is defined in `package.json`, or 'npx node@lts script.js' for ad-hoc execution. Alternatively, use './node_modules/.bin/node script.js'. -
npm ERR! code EEXIST
cause Conflicting global installation when using older npm versions or environmental issues.fixEnsure `npm` is updated to a modern version (>=3.0.0). If installing globally, consider using `npm i --force` cautiously, or preferably, install the `node` package locally as a project dependency to avoid global conflicts. -
npm WARN npm npm does not support Node.js <current-node-version>
cause The installed npm version is incompatible with the currently active Node.js runtime, often seen when switching Node.js versions or having an outdated npm.fixUpdate npm by running `npm install -g npm@latest` using a compatible Node.js version, or ensure your Node.js environment matches the npm's requirements.
Warnings
- breaking Installing 'node' globally with npm@2 will fail due to npm's internal removal process, which attempts to remove the package before its installation scripts can run, causing a conflict.
- gotcha After local installation (`npm i node`), the `node` command in your terminal's global PATH will still refer to your system's globally installed Node.js. The locally installed binary is only automatically used within `npm run` scripts or when explicitly invoked via `npx` or its full path.
- gotcha When using `npx node <script.js>` without a version specifier (e.g., `@lts`, `@20`), `npx` might use a globally installed Node.js, a different locally cached version, or prompt to install the latest available, potentially leading to inconsistent environments.
Install
-
npm install node -
yarn add node -
pnpm add node
Imports
- node (in npm scripts)
import { node } from 'node';{ "scripts": { "start": "node index.js" } } - node (npx execution)
node your-script.js
npx node@lts your-script.js
- node (direct local binary)
node your-script.js
./node_modules/.bin/node your-script.js
Quickstart
// package.json
// {
// "name": "my-local-node-project",
// "version": "1.0.0",
// "scripts": {
// "start": "node index.js",
// "check-local-node": "node -v"
// }
// }
// 1. Install the latest LTS version of Node.js locally
// npm will place the 'node' executable in ./node_modules/.bin/
npm i node@lts
// 2. Create an 'index.js' file:
// index.js
import { readFileSync } from 'node:fs'; // Using 'node:' prefix for clarity
import { join } from 'node:path';
// This confirms the version of Node.js that is executing this script
console.log(`Hello from Node.js version: ${process.version}`);
console.log(`Node.js executable path: ${process.execPath}`);
// Example: Reading a local file
const packageJsonPath = join(process.cwd(), 'package.json');
const packageJsonContent = readFileSync(packageJsonPath, 'utf8');
console.log('Successfully read package.json:', JSON.parse(packageJsonContent).name);
// 3. To run this script using the locally installed Node.js via npm script:
// npm start
// 4. You can also use npx to run a specific version ad-hoc:
// npx node@20 -e "console.log(process.version)"