{"id":12953,"library":"check-node-version","title":"Check Node.js and Package Manager Versions","description":"check-node-version is a utility designed to verify that the currently installed versions of Node.js and various package managers (npm, npx, yarn, and pnpm) meet specified semantic version ranges. It operates both as a command-line interface (CLI) tool for script automation and offers a programmatic API for integration into applications. The current stable version is 4.2.1, indicating a mature and well-established package. Its primary function is to prevent common environment-related issues by providing clear feedback and suggested installation steps (e.g., using `nvm`) when version requirements are not met. This makes it a crucial tool for maintaining consistent development and deployment environments across teams and CI/CD pipelines, differing from simple `node -v` by offering comprehensive checks and actionable advice for multiple tools.","status":"active","version":"4.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/parshap/check-node-version","tags":["javascript","version","semver","typescript"],"install":[{"cmd":"npm install check-node-version","lang":"bash","label":"npm"},{"cmd":"yarn add check-node-version","lang":"bash","label":"yarn"},{"cmd":"pnpm add check-node-version","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary export is a default function. Type definitions are included for TypeScript.","wrong":"import { check } from 'check-node-version';","symbol":"check","correct":"import check from 'check-node-version';"},{"note":"CommonJS require syntax for Node.js environments. The function itself is named 'check' in documentation.","symbol":"check (CommonJS)","correct":"const check = require('check-node-version');"},{"note":"Importing type definitions for programmatic usage, common in TypeScript projects.","symbol":"CliOptions","correct":"import type { CliOptions } from 'check-node-version';"}],"quickstart":{"code":"import check from 'check-node-version';\n\nconst requiredVersions = {\n  node: '>=18.0.0',\n  npm: '>=8.0.0',\n  yarn: '^1.22.0'\n};\n\ncheck(requiredVersions, (error, result) => {\n  if (error) {\n    console.error('An unexpected error occurred:', error);\n    process.exit(1);\n  }\n\n  if (result.isSatisfied) {\n    console.log('All required Node.js and package manager versions are satisfied!');\n    console.log('Current versions:');\n    for (const tool in result.versions) {\n      console.log(`  ${tool}: ${result.versions[tool].version} (Wanted: ${result.versions[tool].wanted})`);\n    }\n    process.exit(0);\n  } else {\n    console.error('Some required Node.js or package manager versions are NOT satisfied:');\n    for (const tool in result.versions) {\n      if (!result.versions[tool].isSatisfied) {\n        console.error(`  ${tool}: Found ${result.versions[tool].version || 'N/A'} (Wanted: ${result.versions[tool].wanted})`);\n        if (result.versions[tool].notSatisfiedVersion) {\n            console.error(`    Suggested fix: ${result.versions[tool].notSatisfiedVersion.message}`);\n        }\n      }\n    }\n    process.exit(1);\n  }\n});","lang":"typescript","description":"This quickstart demonstrates the programmatic API to check Node.js, npm, and yarn versions. It logs success or lists unsatisfied versions with suggested fixes, exiting with an appropriate status code."},"warnings":[{"fix":"Ensure all tools (Node.js, npm, npx, yarn, pnpm) are installed with semver-compliant version strings. Update problematic tools if necessary.","message":"When checking versions of tools like Yarn, if a non-semver-compliant version string is encountered, `check-node-version` may treat it as a 'missing tool' and report an error, rather than attempting to parse an invalid version. This is by design to ensure strict semver adherence.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Review and update the `engines` field in your `package.json` to reflect realistic and supported version ranges, or ensure Volta pins are current if using `--volta`.","message":"Using the `--package` or `--volta` CLI options (or their programmatic equivalents) will make `check-node-version` strictly adhere to the `engines` field in `package.json` or versions pinned by Volta. This can sometimes lead to failures if the `engines` field specifies a very narrow or outdated range, even if a compatible-but-not-exact version is installed.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always verify the appropriate version management or installation method for your specific environment when `check-node-version` reports a version mismatch.","message":"The suggestions provided by `check-node-version` (e.g., `nvm install X`) are generic and might not be applicable to all environments or operating systems. Users in managed environments, CI/CD pipelines, or specific OS setups might need to use alternative installation methods.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"N/A - This indicates stability; focus on keeping your Node.js ecosystem tools updated.","message":"There have been no significant breaking changes introduced within `check-node-version` itself across its major versions that would typically halt or alter its core functionality since its initial stable releases. The package maintains high backward compatibility for its primary use cases. Any 'breaking changes' are usually related to updates in Node.js or package manager versions, not the utility's API.","severity":"breaking","affected_versions":"N/A"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use a version manager (e.g., `nvm install <version>`, `nvm use <version>`) or update your global Node.js/package manager installation to meet the required range. The output typically provides a direct suggestion.","cause":"The currently installed Node.js version (or other tool) does not satisfy the specified semantic version range.","error":"Error: Wanted node version X.X.X (>=X.X.X <Y.Y.Y)"},{"fix":"If installed locally, run with `npx check-node-version ...` or `npm run check-node-version ...` if defined in `package.json` scripts. If intended for global use, ensure it's installed globally: `npm install -g check-node-version`.","cause":"The `check-node-version` executable is not in your system's PATH, or the package was not installed globally or locally linked correctly.","error":"check-node-version: command not found"},{"fix":"Inspect the `result.versions` object within your callback to identify which specific tool(s) failed and their respective `notSatisfiedVersion.message` for remediation. The example quickstart code demonstrates this.","cause":"When using the programmatic API, this message indicates that `result.isSatisfied` was false, meaning one or more of the checked tools did not meet their version requirements.","error":"Some package version(s) failed!"},{"fix":"Update the problematic tool (Y) to a version that reports a semver-compliant string. Some older or custom builds of package managers might exhibit this issue. Alternatively, consider checking only semver-compliant tools or adjusting the check logic if strict semver isn't crucial for that specific tool.","cause":"The version string reported by tool Y (e.g., Yarn) is not a valid semantic version, preventing `check-node-version` from parsing it correctly.","error":"Error: Could not parse version X.X.X for Y"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"check-node-version"}