Table of Contents
Whether you’re debugging compatibility issues, ensuring you’re running the right version for a project, or just curious about your current setup, knowing how to check your Node.js version and package manager versions is essential for any Node.js developer.
Why version checking matters
Knowing your versions is crucial for several reasons:
- Compatibility: Different projects may require specific Node.js or package manager versions
- Feature availability: Newer versions include new features and improvements
- Security: Keeping track of versions helps ensure you’re running secure, up-to-date software
- Debugging: Version mismatches are often the cause of unexpected behavior
- Project requirements: Many projects specify minimum version requirements in their documentation
- Support and maintenance: This is critical - according to the official Node.js releases roadmap, production applications should only use Active LTS or Maintenance LTS releases
The Node.js project follows a predictable release cycle where:
- Major versions are “Current” for six months
- Odd-numbered releases become unsupported after six months
- Even-numbered releases move to “Active LTS” with critical bug fixes guaranteed for 30 months
- Older, unsupported versions may have unaddressed security vulnerabilities
Always ensure you’re running a currently supported version to get the best security, stability, and access to critical bug fixes. Check the Node.js releases page regularly to stay informed about your version’s support status.
In this article, we’ll cover the simple commands to check versions of Node.js and popular package managers including npm, pnpm, and yarn.
Checking Node.js version
The most straightforward way to check your Node.js version is using the --version
or -v
flag:
node --version# ornode -v
This will output something like:
v20.11.0
Getting more detailed version information
To see all the compilation and runtime information, you can use the -p
flag (short for --print
), which evaluates a script and prints the result:
node -p process.version
You can also get comprehensive version information including V8, OpenSSL, and other dependencies:
node -p process.versions
This will output a detailed object with information about all the underlying components.
Getting Node.js version from code
When writing Node.js applications, you might need to check the version programmatically:
// Get the Node.js versionconsole.log('Node.js version:', process.version)
// Get all version informationconsole.log('All versions:', process.versions)
// Check if running a specific major versionconst majorVersion = parseInt(process.version.slice(1))if (majorVersion >= 24) { console.log('Running Node.js 24 or newer')}
// Or if you want to extract major, minor, and patch versions as numbersconst [major, minor, patch] = process.version .substring(1) .split('.') .map((s) => Number.parseInt(s, 10))
console.log(`Major: ${major}, Minor: ${minor}, Patch: ${patch}`)
This is particularly useful for conditional features or compatibility checks in your applications.
Checking package manager versions
Modern Node.js development relies heavily on package managers. Here’s how to check the versions of the most popular ones:
npm (Node Package Manager)
npm comes bundled with Node.js, so if you have Node.js installed, you likely have npm too:
npm --version# ornpm -v
Example output:
10.2.4
pnpm
pnpm is a fast, space-efficient package manager that uses hard linking from a single content-addressable storage to save disk space and speed up installations. It’s up to 2x faster than npm and provides stricter dependency management.
Full disclaimer, pnpm is my favorite package manager these days and it powers the dependency management of this very site, so check it out if you haven’t already! 😊
If you have pnpm installed, check its version with:
pnpm --version# orpnpm -v
Example output:
9.12.0
yarn
Yarn is a modern package and project manager focused on providing stable, reproducible installations with excellent workspace management for projects of all sizes, from simple applications to enterprise monorepos.
For yarn users:
yarn --version# oryarn -v
Example output:
1.22.19
Upgrading your versions
If you discover you need to upgrade your Node.js version or install a different package manager, check out our comprehensive guide on 5 Ways to install Node.js which covers various installation and upgrade methods including version managers like nvm and n.
Summary
Checking versions is a quick but essential task for Node.js developers:
- Node.js:
node --version
ornode -v
- npm:
npm --version
ornpm -v
- pnpm:
pnpm --version
orpnpm -v
- yarn:
yarn --version
oryarn -v
Keep these commands handy, and you’ll always know what versions you’re working with!