Find the installed version of an npm package
By Flavio Copes
Find the installed version of an npm package with npm list, print the whole dependency tree with npm list --all, and check the registry with npm view.
To find the installed version of an npm package, run npm list followed by the package name, inside the project folder. Run it without a name to see the version of every package you installed.
List your installed packages
To see the version of all the top-level npm packages installed, the ones you listed in your package.json:
npm list
Example:
❯ npm list
cowsay-app@1.0.0 /Users/flavio/dev/node/cowsay
└── cowsay@1.6.0
Recent versions of npm (7 and up) only print your direct dependencies by default. To see the whole dependency tree, with the dependencies of your dependencies, add the --all flag:
❯ npm list --all
cowsay-app@1.0.0 /Users/flavio/dev/node/cowsay
└─┬ cowsay@1.6.0
├── get-stdin@8.0.0
├─┬ string-width@2.1.1
│ ├── is-fullwidth-code-point@2.0.0
│ └─┬ strip-ansi@4.0.0
│ └── ansi-regex@3.0.1
├── strip-final-newline@2.0.0
└─┬ yargs@15.4.1
...
Older npm versions printed this full tree by default, and you limited it with npm list --depth=0.
You could also open the package-lock.json file, which records the exact resolved version of everything, but that involves some visual scanning.
npm list -g is the same, but for globally installed packages.
Get the version of a specific package
Specify the package name:
❯ npm list cowsay
cowsay-app@1.0.0 /Users/flavio/dev/node/cowsay
└── cowsay@1.6.0
This also works for dependencies of packages you installed, and shows you every place where the package appears in the tree:
❯ npm list string-width
cowsay-app@1.0.0 /Users/flavio/dev/node/cowsay
└─┬ cowsay@1.6.0
├── string-width@2.1.1
└─┬ yargs@15.4.1
└── string-width@4.2.3
Why not just check package.json? Because it stores the version range you asked for, like ^1.6.0, not the version actually sitting in node_modules right now. npm list tells you the real one. The two can differ.
Check the latest version available on npm
If you want to see what’s the latest available version of the package on the npm registry, run npm view [package_name] version:
❯ npm view cowsay version
1.6.0
Be careful with this one: npm view queries the registry, not your project. It tells you the newest published release, which might be ahead of what you have installed. Mixing the two up is a common source of “but I thought I was on the latest version” confusion.
To compare installed versus latest for the whole project in one shot, run npm outdated.
Related posts about node: