---
title: "How do I check which version of a package is installed?"
description: "Run npm ls with the package name to see the installed version, npm view to see the latest published one, and npm outdated to compare everything in your project at once."
url: https://www.danny.engineering/answer/nodejs/how-do-i-check-which-version-of-a-package-is-installed
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T20:30:00.000Z
tags: ["Node.js"]
---

# How do I check which version of a package is installed?

## The short answer


Run `npm ls` with the package name from your project folder. It shows the version actually installed in `node_modules`, including any nested copies.


```bash
npm ls react
# my-app@1.0.0 /Users/me/my-app
# └── react@19.2.0
```


Use `npm view react version` to see the latest version on the registry, and `npm outdated` to compare everything at once.


## Why it happens


There are three different version numbers you might mean, and they are often not the same:

- **The range in package.json**, such as `^19.0.0`. This is what you allow, not what you have.
- **The installed version** in `node_modules`, which is recorded in `package-lock.json`. This is what your code actually runs.
- **The latest published version** on the npm registry.

On top of that, the same package can be installed more than once. If your app needs one version and a dependency needs another, npm installs both in different places in the tree. Looking only at `package.json` hides all of this, which is why the tools below are more reliable.


## How to fix it


### See the installed version with npm ls


```bash
# One package, every copy in the tree
npm ls lodash

# Only your direct dependencies
npm ls --depth=0

# Every package, including nested ones
npm ls --all

# Globally installed packages
npm ls -g --depth=0
```


If a package appears more than once with different versions, `npm ls` shows each copy under the package that needs it. Add `--json` if you want to read the output from a script.


### Find out why a version is installed


When you see a version you did not expect, `npm explain` (also available as `npm why`) shows the chain of packages that pulled it in.


```bash
npm explain lodash
```


This is useful when a security audit flags an old version deep in the tree.


### See published versions with npm view


`npm view` asks the registry, so it works even if the package is not installed.


```bash
# Latest version
npm view react version

# Every published version
npm view react versions

# Release tags such as latest, next or canary
npm view react dist-tags
```


### Compare everything with npm outdated


`npm outdated` lists every dependency that is behind, with three columns:


```bash
npm outdated
# Package  Current  Wanted  Latest
# vitest   3.1.0    3.2.4   4.0.8
```

- **Current** is what is installed.
- **Wanted** is the newest version your `package.json` range allows. `npm update` moves you here.
- **Latest** is the newest version published. Getting there may need `npm install name@latest`, and it may include breaking changes.

The numbers above are only an example; you will see your own.


### Check the version from code


Sometimes you need the version at runtime, for example in a bug report. Many packages let you import their `package.json`:


```javascript
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
console.log(require('react/package.json').version);
```


This fails with `ERR_PACKAGE_PATH_NOT_EXPORTED` if the package uses an `exports` field that does not include `package.json`. In that case, use `npm ls` instead, or read your own lockfile.


## Common pitfalls

- **Trusting package.json.** `^1.2.0` might mean 1.9.3 is installed. Check with `npm ls`.
- **Running in the wrong folder.** `npm ls` reports the project in the current directory. In a monorepo, run it in the workspace you care about, or use `--workspaces`.
- **Confusing local and global.** A command line tool might be installed globally at one version and locally at another. `npx` prefers the local one. Check both with `npm ls name` and `npm ls -g name`.
- **Assuming one copy.** Two copies of a library like React in one app cause strange errors. Look for duplicates in `npm ls` output.
- **Using pnpm or Yarn.** Their equivalents are `pnpm list` and `yarn why`. The npm commands read npm's own lockfile.

## Related reading

- [npm docs: npm ls](https://docs.npmjs.com/cli/commands/npm-ls)
- [npm docs: npm outdated](https://docs.npmjs.com/cli/commands/npm-outdated)
