{"id":14762,"library":"node","title":"Local Node.js Binary Installer","description":"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.","status":"active","version":"24.15.0","language":"javascript","source_language":"en","source_url":"https://github.com/aredridel/node-bin-gen","tags":["javascript","runtime"],"install":[{"cmd":"npm install node","lang":"bash","label":"npm"},{"cmd":"yarn add node","lang":"bash","label":"yarn"},{"cmd":"pnpm add node","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package provides a command-line executable, not JavaScript modules. Incorrectly attempting to 'import' or 'require' 'node' as a module will fail. npm scripts correctly place the local binary in PATH.","wrong":"import { node } from 'node';","symbol":"node (in npm scripts)","correct":"{\n  \"scripts\": {\n    \"start\": \"node index.js\"\n  }\n}"},{"note":"npx provides a convenient way to execute specific versions of the 'node' binary without local installation, or to temporarily use a locally installed version. Always specify the version for clarity, e.g., 'node@lts' or 'node@20', as omitting it might use a global or cached version.","wrong":"node your-script.js","symbol":"node (npx execution)","correct":"npx node@lts your-script.js"},{"note":"After 'npm i node', the executable is placed in './node_modules/.bin/'. Directly invoking 'node' without 'npm run' or 'npx' will only work if './node_modules/.bin/' is manually added to your shell's PATH, which is generally not recommended for project-specific binaries.","wrong":"node your-script.js","symbol":"node (direct local binary)","correct":"./node_modules/.bin/node your-script.js"}],"quickstart":{"code":"// package.json\n// {\n//   \"name\": \"my-local-node-project\",\n//   \"version\": \"1.0.0\",\n//   \"scripts\": {\n//     \"start\": \"node index.js\",\n//     \"check-local-node\": \"node -v\"\n//   }\n// }\n\n// 1. Install the latest LTS version of Node.js locally\n// npm will place the 'node' executable in ./node_modules/.bin/\nnpm i node@lts\n\n// 2. Create an 'index.js' file:\n// index.js\nimport { readFileSync } from 'node:fs'; // Using 'node:' prefix for clarity\nimport { join } from 'node:path';\n\n// This confirms the version of Node.js that is executing this script\nconsole.log(`Hello from Node.js version: ${process.version}`);\nconsole.log(`Node.js executable path: ${process.execPath}`);\n\n// Example: Reading a local file\nconst packageJsonPath = join(process.cwd(), 'package.json');\nconst packageJsonContent = readFileSync(packageJsonPath, 'utf8');\nconsole.log('Successfully read package.json:', JSON.parse(packageJsonContent).name);\n\n// 3. To run this script using the locally installed Node.js via npm script:\n// npm start\n\n// 4. You can also use npx to run a specific version ad-hoc:\n// npx node@20 -e \"console.log(process.version)\"\n","lang":"typescript","description":"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."},"warnings":[{"fix":"Upgrade npm to version 3 or higher before attempting global installation, or install 'node' locally within a project's `devDependencies`.","message":"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.","severity":"breaking","affected_versions":"<3.0.0"},{"fix":"Always use `npm run <script-name>` for scripts defined in `package.json` or `npx node@<version> <command>` for ad-hoc execution to ensure the project's local Node.js version is used.","message":"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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always specify the desired Node.js version when using `npx`, e.g., `npx node@lts myscript.js` or `npx node@20 myscript.js`, to guarantee the intended runtime.","message":"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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use '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'.","cause":"Attempting to run 'node script.js' directly in the shell after local installation without using 'npm run' or 'npx'.","error":"Error: command not found: node"},{"fix":"Ensure `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.","cause":"Conflicting global installation when using older npm versions or environmental issues.","error":"npm ERR! code EEXIST"},{"fix":"Update 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.","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.","error":"npm WARN npm npm does not support Node.js <current-node-version>"}],"ecosystem":"npm"}