Reputation: 33678
How can I find the version of an installed Node.js or npm package?
This prints the version of npm itself:
npm -v <package-name>
This prints a cryptic error:
npm version <package-name>
This prints the package version on the registry (i.e., the latest version available):
npm view <package-name> version
How do I get the installed version?
Upvotes: 3058
Views: 2329165
Reputation: 13298
You can define this alias in your terminal:
alias phas='npm list | grep'
phas lod
├── [email protected]
Upvotes: -3
Reputation: 1413
WARNING: This answer shows the latest available version of a module in npm, not the currently installed version locally.
npm view <package-name> version
npm view redux version
I have version 7.2.0 of Redux.
Upvotes: 35
Reputation: 143
To get only the installed version number, try:
npm list --depth=0 packagename | grep packagename | cut -d'@' -f2
E.g., the installed version number of PM2:
npm list --depth=0 pm2 | grep pm2 | cut -d'@' -f2
And to list globally installed packages, add the -g
flag to the npm list
command, eg:
npm list -g --depth=0 packagename | grep packagename | cut -d'@' -f2
Upvotes: 6
Reputation: 23825
You can access the package.json or bower.json file of the package with:
notepad
installed):notepad ./node_modules/vue-template-compiler/package.json`
This will open the package.json
in Notepad which has the version number of the packageName you included in the command.
cat node_modules/prettier/package.json | grep version
This will output something like this:
Upvotes: 4
Reputation: 561
You can see file package.json to see installed packages versions.
To get the list on the command line,
npm ls
It will give you all installed packages in a project with their respective versions.
For a particular package version,
npm ls <package-name>
For example,
npm ls next
It will return version
-- [email protected]
Upvotes: 40
Reputation: 1775
I am using
npm list --depth=0 | grep module_name@
It brings me results like this:
[email protected]
Upvotes: 4
Reputation: 514
If you'd like to check for a particular module installed globally, on Unix-like systems use:
npm list -g --depth=0 | grep <module_name>
Upvotes: 6
Reputation: 2890
I've seen some very creative answers, but you can just do this (for global packages add the --global switch):
npm ls package
Example:
npm ls babel-cli
Output:
`-- [email protected]
The npm documentation says that npm -ls
This command will print to stdout all the versions of packages that are installed, as well as their dependencies, in a tree-structure.
Upvotes: 20
Reputation: 159
I've built a tool that does exactly that - qnm.
node_modules
directory.Install it using:
npm i --global qnm
And run:
qnm [module]
For example:
qnm lodash
Output:
lodash
├── 4.17.5
├─┬ cli-table2
│ └── 3.10.1
└─┬ karma
└── 3.10.1
Which means we have lodash
installed in the root of the node_modules folder folder and two other copies in the node_modules folder of cli-table2
and karma
.
It's really fast and has some nice features, like tab completion and match search.
Upvotes: 12
Reputation: 2707
For local packages:
npm list --depth=0
For global packages:
npm list -g --depth=0
Upvotes: 35
Reputation: 3633
npm list --depth 0
is the command which shows all libraries with version, but you can use npm-check
.
npm-check is a good library to manage all those things regarding the version system event. It will show libraries versions, new version updates, and unused versions, and many more.
To install it, just run:
npm install -g npm-check
And simply run
npm-check
Check the screenshot. It is showing everything about the package versions, new version updates, and unused versions.
It works globally too. Give it a try.
Upvotes: 13
Reputation: 1323
This is a simple question and should have a simpler answer than what I see in previous answers.
To see the installed npm packages with their version, the command is npm ls --depth=0
, which, by default, displays what is installed locally. To see the globally installed packages, add the -global
argument: npm ls --depth=0 -global
.
--depth=0
returns a list of installed packages without their dependencies, which is what you're wanting to do most of the time.
ls
is the name of the command, and list
is an alias for ls
.
Upvotes: 7
Reputation: 9539
Combining some of the above answers and produces a super simple and super quick lookup.
Run from the project root. There isn’t any need to cd
into any folder, just one line:
node -p "require('SOMEPACKAGE/package.json').version"
Upvotes: 29
Reputation: 8904
I added this to my .bashrc file:
function npmv {
case $# in # Number of arguments passed
0) v="$(npm -v)" ; # Store output from npm -v in variable
echo "NPM version is: $v"; # Can't use single quotes
# ${v} would also work
;;
1) s="$(npm list --depth=0 $1 | grep $1 | cut -d @ -f 2)";
echo "$s";
;;
2) case "$2" in # Second argument
g) #global| # Syntax to compare bash string to literal
s="$(npm list --depth=0 -g $1 | grep $1 | cut -d @ -f 2)";
echo "$s";
;;
l) #Latest
npm view $1 version; # 'npm info $1 version' does the same thing
;;
*) echo 'Invalid arguments';
;;
esac;
;;
*) echo 'Invalid arguments';
;;
esac;
}
export -f npmv
Now all I have to do is type:
NPM version is: 4.2.0
0.8.08
0.8.09
0.8.10
Note -d on the cut command means delimit by, followed by @, and then f means field. The '2' means the second field since there will be one either side of the @ symbol.
Upvotes: 7
Reputation: 6245
From the root of the package do:
node -p "require('./package.json').version"
(So you need to cd
into the module's home directory if you are not already there. If you have installed the module with npm install
, then it will be under node_modules/<module_name>
.)
Upvotes: 97
Reputation: 379
If you are brave enough (and have Node.js installed), you can always do something like:
echo "console.log(require('./package.json').version);" | node
This will print the version of the current package. You can also modify it to go insane, like this:
echo "eval('var result='+require('child_process').execSync('npm version',{encoding:'utf8'})); console.log(result.WHATEVER_PACKAGE_NAME);" | node
That will print the version of WHATEVER_PACKAGE_NAME
package, that is seen by npm version
.
Upvotes: 15
Reputation: 1617
You can use npm view [module] version, npm info [module] version, npm show [module] version or npm v [module] version to check the version on an installed npm module.
Let's suppose my Grunt module version is the 0.4.5:
npm view grunt version => 0.4.5
npm info grunt version => 0.4.5
npm show grunt version => 0.4.5
npm v grunt version => 0.4.5
Upvotes: 2
Reputation: 20390
Here's a portable Unix (using grep
and sed
) one-liner that returns the version string of a globally-installed npm package (remove the g
from -pg
to query local packages instead):
npm ll -pg --depth=0 grunt | grep -o "@.*:" | sed 's/.$//; s/^.//'
Output:
0.4.5
npm ll
outputs a parsable string formatted like: /usr/lib/node_modules/npm:[email protected]:
;grep
command extracts the value between @
and :
, inclusive;sed
command removes the surrounding characters.Upvotes: 9
Reputation: 14571
If you agree to install jq, you can use the JSON output of npm list
:
npm -j ls <package-name> | jq -r .version
Or, if you want to be verbose:
npm --json list <package-name> | jq --raw-output '.version'
For instance:
npm -j ls ghost | jq -r .version
Output:
0.4.2
Also, the JSON format is slightly different for global packages, so you'll need to change the query.
For instance:
npm -j -g ls | jq -r .dependencies.ghost.version
Output:
0.4.2
Upvotes: 24
Reputation: 1596
I just used
npm list | grep <package name>
and it worked great.
On Windows, run:
npm list | find <package name>
In PowerShell run:
npm list | sls <package name>
Upvotes: 84
Reputation: 2799
Use
npm info YOUR_PACKAGE version
E.g.,
npm info grunt version
0.4.5
Upvotes: 113
Reputation: 63159
Use npm list
for local packages or npm list -g
for globally installed packages.
You can find the version of a specific package by passing its name as an argument. For example, npm list grunt
will result in:
projectName@projectVersion /path/to/project/folder
└── [email protected]
Alternatively, you can just run npm list
without passing a package name as an argument to see the versions of all your packages:
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ └── [email protected]
└── [email protected]
You can also add --depth=0
argument to list installed packages without their dependencies.
Upvotes: 3455
Reputation: 222841
npm view <package> version
- returns the latest available version on the package.
npm list --depth=0
- returns versions of all installed modules without dependencies.
npm list
- returns versions of all modules and dependencies.
And lastly to get the Node.js version: node -v
Upvotes: 299
Reputation: 13465
Another quick way of finding out what packages are installed locally and without their dependencies is to use:
npm list --depth=0
Which gives you something like
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
Obviously, the same can be done globally with npm list -g --depth=0
.
This method is clearer if you have installed a lot of packages.
To find out which packages need to be updated, you can use npm outdated -g --depth=0
.
Upvotes: 1046
Reputation: 169
npm list package-name gives the currently installed version
Upvotes: 11
Reputation: 2365
To list local packages with the version number use:
npm ls --depth=0
To list global packages with the version number use:
npm ls -g --depth=0
Upvotes: 14
Reputation: 1171
You can also check the version with this command:
npm info <package name> version
Upvotes: 21
Reputation: 1261
You may try this:
npm show {package} version
shows the latest package version.
And if your package is outdated, npm outdated
will show it with version info.
Upvotes: 2