Find the version of an installed npm package
How can I find the version of an installed Node.js or npm package? This prints the version of npm itself:
On my installation, «npm -v
most of the time
34 Answers 34
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 └── grunt@0.4.1
Alternatively, you can just run npm list without passing a package name as an argument to see the versions of all your packages:
├─┬ cli-color@0.1.6 │ └── es5-ext@0.7.1 ├── coffee-script@1.3.3 ├── less@1.3.0 ├─┬ sentry@0.1.2 │ ├── file@0.2.1 │ └── underscore@1.3.3 └── uglify-js@1.2.6
You can also add —depth=0 argument to list installed packages without their dependencies.
On mac and linux it’s nice to add » | grep module_name», to filter the desired module version. Especially when running globally with -g. For example: «npm list -g | grep express» to get the installed express version.
Per @guya’s tip for *nix based systems, on Windows you can use PowerShell for similar results: | select-string module_name to filter the module. Or, if you’re using Git Bash (or just Bash, for that matter), you can use grep .
If you can’t remember list , npm ls also works. In fact, many npm commands have aliases, and moreover, if you type a substring of a command, if this substring is unambiguous, it will work also; for instance npm ls , npm list , npm lis are all the same. If you want more verbose output, try npm ll (but probably you want —depth=0 added to it).
The output isn’t the best for parsing with a script. Is there really not a way to get an output that is just the package version without having to do something like npm list -g | awk -F@ ‘/
Another quick way of finding out what packages are installed locally and without their dependencies is to use:
Which gives you something like
├── bower@0.8.6 ├── grunt@0.4.1 ├── grunt-bower-requirejs@0.4.3 ├── grunt-contrib-clean@0.4.1 ├── grunt-contrib-coffee@0.7.0 ├── grunt-contrib-copy@0.4.1 ├── grunt-contrib-imagemin@0.1.4 ├── grunt-contrib-jshint@0.1.1 ├── grunt-contrib-livereload@0.1.2 ├── grunt-contrib-requirejs@0.4.1 ├── grunt-regarde@0.1.1 └── grunt-svgmin@0.1.0
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 .
@ygaradon Correct, but the —depth=0 makes it faster, because it does not have to recursively load dependencies
npm view 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
npm view
@AlexanderMills True, but having it here avoids another search for that. Btw, npm v , npm info and npm show are all alias of npm view .
along the same lines, npm view
npm info YOUR_PACKAGE version
npm info grunt version 0.4.5
Agree with @tanner-semerad. I checked into Docs of npm to clearify it. npm info is alias for npm view and in Docs of npm you will find that standing: This command shows data about a package and prints it to the stream referenced by the outfd config, which defaults to stdout. [. ] The default version is «latest» if unspecified. That’s way I vote down.
No, as mentioned this will show the latest version on the registry. This «seems» to work if by chance your local dependency is on the latest version. But if it’s not, you will not see the actual installed (older) version with this command.
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/ .)
Nice! Quite a bit faster than running «npm list» as the other answers suggest (~1s instead of ~20s) — at least when you have this code snippet ready! (there should really be an npm plugin to do this. )
I’d like to oppose @geedew ‘s comment. This answer suggests to be run in the root folder of the installed module. In the package.json of the installed module you will(!) find the actually installed version.
For Windows users: npm list -g —depth=0 |find «» Note the double quotes
WARNING: This answer shows the latest available version of a module in npm, not the currently installed version locally.
It’s very simple.. Just type the below line
Example
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»
You can see file package.json to see installed packages versions.
To get the list on the command line,
It will give you all installed packages in a project with their respective versions.
For a particular package version,
If you agree to install jq, you can use the JSON output of npm list :
Or, if you want to be verbose:
npm --json list | jq --raw-output '.version'
npm -j ls ghost | jq -r .version
Also, the JSON format is slightly different for global packages, so you’ll need to change the query.
npm -j -g ls | jq -r .dependencies.ghost.version
You can also check the version with this command:
Again, it shows the latest version available in the package registry not the version of the currently installed package.
I’ve seen some very creative answers, but you can just do this (for global packages add the —global switch):
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.
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',)); console.log(result.WHATEVER_PACKAGE_NAME);" | node
That will print the version of WHATEVER_PACKAGE_NAME package, that is seen by npm version .
To list local packages with the version number use:
To list global packages with the version number use:
To see all the installed packages locally or globally, use these commands:
- npm list for local packages or npm list -g for globally installed packages.
- npm list —depth=0
- npm list | sls
- node -v
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.
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.
I’ve built a tool that does exactly that — qnm.
qnm — A simple CLI utility for querying the node_modules directory.
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.
npm list --depth 1 --global packagename
npm list package-name gives the currently installed version
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/^.//'
- the npm ll outputs a parsable string formatted like: /usr/lib/node_modules/npm:npm@2.14.8: ;
- the grep command extracts the value between @ and : , inclusive;
- the sed command removes the surrounding characters.
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 .
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 # $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:
- npmv for the version of npm, for example, NPM version is: 4.2.0
- npmv for the local version, for example, 0.8.08
- npmv g for global version, for example, 0.8.09
- npmv l for latest version, for example, 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.
How do I find out which version of a driver is included in a kernel?
I need to find out which driver/module version is contained in a kernel which isn’t installed. Is there a document in the source that contains this or something listed online that haven’t been able to find?
You’re going at this the wrong way. Read this. Use the tools I listed in the troubleshooting section, then from the output tell us what isn’t working.
@eyoung100 It isn’t a matter of troubleshooting. I was asked by one of our dedicated Red Hat resources which driver version is provided by the latest kernel found at kernel.org. Again, this isn’t for running kernels. I know how to obtain that information. I need to know how to determine what a kernel will provide prior to installation. Release notes that list driver versions or similar documentation.
@michas the fnic driver. I was asked to determine which driver version is provided in the source downloaded from kernel.org.
2 Answers 2
You can use the modinfo command to give you all kind of information about a given module.
$ modinfo bluetooth filename: /lib/modules/3.17.4-1-ARCH/kernel/net/bluetooth/bluetooth.ko.gz alias: net-pf-31 license: GPL version: 2.19 description: Bluetooth Core ver 2.19 author: Marcel Holtmann srcversion: 4D63C2C41C55E984E7057A5 depends: rfkill,crc16 intree: Y vermagic: 3.17.4-1-ARCH SMP preempt mod_unload modversions parm: disable_esco:Disable eSCO connection creation (bool) parm: disable_ertm:Disable enhanced retransmission mode (bool)
However most of the time you will not find any explicit version, because the module is simply the one contained in your kernel source tree.