Local Node.js Binary Installer

24.15.0 · active · verified Sun Apr 19

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

Warnings

Install

Imports

Quickstart

Demonstrates installing a local Node.js binary and running a simple script with it via `npm start`, confirming the `process.version` and `process.execPath` to verify local execution. Also shows ad-hoc `npx` usage.

// 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)"

view raw JSON →