2931

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Laurent Couvidou
  • 32,354
  • 3
  • 30
  • 46
  • 23
    On my installation, "npm -v " reports the version of npm, itself. To list the latest version of a package in the registry, I have found that "npm view version" gets the job done. – David A. Gray Apr 29 '18 at 20:25
  • 26
    `npm show` shows the latest in npm, not installed – Tsagana Nokhaeva Aug 26 '19 at 16:18
  • 2
    most of the time -v should work. However, this depends on whether or not the package developer(s) added cli functionality to their packages. – Nate T Dec 21 '20 at 07:39
  • If you're in the directory that its package.json is in, you can use `npm pkg get version`. – Jason C Nov 14 '22 at 23:31

35 Answers35

3347

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
TheHippo
  • 61,720
  • 15
  • 75
  • 100
  • 152
    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. – guya Apr 16 '13 at 01:51
  • 111
    If you want a specific module, you can run it like `npm list less-middleware` as an example. – juanpaco Mar 16 '14 at 19:43
  • 15
    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`. – Noel Feb 12 '16 at 20:33
  • 16
    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). – jakub.g May 16 '16 at 18:35
  • 2
    this always gives "npm ERR! 1" for me, both with and without `-g` – roberto tomás Sep 15 '16 at 03:44
  • For Windows you can also use `| findstr "module_name"`´, but using the `npm list [-g] ` solution given by @juanpaco above works better. – Saborknight Dec 13 '16 at 20:21
  • 7
    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@ '// { print $2}'` – Thayne Nov 07 '17 at 19:09
  • 3
    Currentliy npm 5.5.1 has a --parseable option. Try `npm ls --depth=0 --parseable`. See [doc](https://docs.npmjs.com/cli/ls). – taz Jan 05 '18 at 04:38
  • 1
    @taz `--parseable` option is not showing the version of the installed package! (npm 6.14) – brainless Apr 26 '21 at 10:01
  • 1
    @guya Windows also has a way to filter like grep in Linux. e.g. `npm list | find "module_name"` from the command prompt – Panama Jack Oct 09 '21 at 02:40
  • With turbo I had to use --pattern `npm list --pattern grunt` – Ray Foss Nov 11 '22 at 06:21
1029

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

├── 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Patrik Affentranger
  • 13,245
  • 2
  • 22
  • 25
288

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
  • 29
    npm view version, goes to the npm remote registry, not local filesystem... – Alexander Mills Dec 05 '16 at 09:19
  • @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`](https://docs.npmjs.com/cli/view). – CPHPython Jan 17 '18 at 10:38
  • along the same lines, `npm view versions` will return all the versions for the package and not just the latest one. – rgantla Jul 06 '20 at 19:52
109

Use

npm info YOUR_PACKAGE version

E.g.,

npm info grunt version

0.4.5
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David Beckwith
  • 2,679
  • 1
  • 17
  • 11
  • 173
    This doesn't show the installed package version, it just shows the latest available version. – Tanner Semerad Aug 22 '15 at 16:56
  • 2
    Agree with @tanner-semerad. I checked into [Docs of npm](https://docs.npmjs.com/cli/view) to clearify it. `npm info` is alias for `npm view` and in [Docs of npm](https://docs.npmjs.com/cli/view) 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. – dannydedog Jul 06 '18 at 12:25
  • Shows the latest version available, not latest installed. Downvoted. – lofihelsinki Nov 29 '18 at 06:02
  • 2
    `npm info YOUR_PACKAGE version` The only one that worked :) – GOXR3PLUS Jan 29 '19 at 15:28
  • same, 'npm info YOUR_PACKAGE version' The only one that worked – Jonas Jan 07 '20 at 07:59
  • 1
    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. – Alexander Klimetschek Jun 01 '20 at 18:16
85

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>.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Fergie
  • 5,933
  • 7
  • 38
  • 42
  • 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...) – Venryx May 09 '17 at 10:06
  • 2
    or `node -p "require('./package.json').version"` – Jeff Dickey Jul 05 '17 at 21:14
  • 7
    This won't get the actual version installed if there is a range delimiter like ^ ~ – geedew Mar 22 '19 at 23:23
  • 1
    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. – Michael K Mar 08 '21 at 16:46
80

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>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
chrissavage
  • 1,536
  • 1
  • 14
  • 20
36

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

npm view <package-name> version

Example

npm view redux version

I have version 7.2.0 of Redux.

deanWombourne
  • 38,189
  • 13
  • 98
  • 110
Daksh Patel
  • 1,266
  • 10
  • 9
31

For local packages:

npm list --depth=0

For global packages:

npm list -g --depth=0
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Farhan Yaseen
  • 2,507
  • 2
  • 22
  • 37
30

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

-- next@10.1.3
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Snow
  • 411
  • 5
  • 8
29

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"

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JoshuaDavid
  • 8,861
  • 8
  • 47
  • 55
  • This gives me the error "Package subpath './package.json' is not defined by "exports" in /path/to/SOMEPACKAGE/package.json". Did this used to work until a new node version broke it, or am I doing something wrong? – Bbrk24 Aug 22 '23 at 04:40
23

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Benoit Blanchon
  • 13,364
  • 4
  • 73
  • 81
20

You can also check the version with this command:

npm info <package name> version

jaume
  • 381
  • 1
  • 5
  • 11
Sobin Sunny
  • 1,121
  • 10
  • 14
17

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:

`-- babel-cli@6.26.0

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.

NPM documentation

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Charles Owen
  • 2,403
  • 1
  • 14
  • 25
15

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
KundraLaci
  • 379
  • 4
  • 6
14

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

Lahiru Mirihagoda
  • 1,113
  • 1
  • 16
  • 30
kavigun
  • 2,219
  • 2
  • 14
  • 33
13

To see all the installed packages locally or globally, use these commands:

  1. npm list for local packages or npm list -g for globally installed packages.
  2. npm list --depth=0
  3. npm list | sls <package name>
  4. node -v
DivideByZero
  • 535
  • 4
  • 14
Shekhar Tyagi
  • 1,644
  • 13
  • 18
12

I've built a tool that does exactly that - qnm.

qnm - A simple CLI utility for querying the 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ran Yitzhaki
  • 159
  • 1
  • 5
12

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.

Enter image description here

It works globally too. Give it a try.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mahendra Pratap
  • 3,174
  • 5
  • 23
  • 45
11

Try with:

npm list --depth 1 --global packagename
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eduardo Cuomo
  • 17,828
  • 6
  • 117
  • 94
10

npm list package-name gives the currently installed version

Nandhiny Durai
  • 159
  • 2
  • 5
9

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
  • 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.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
wjordan
  • 19,770
  • 3
  • 85
  • 98
  • With newer versions of npm, there is no trailing colon, so the pipeline is just `| grep -o "@.*" | sed 's/^.//'`. – Bbrk24 Aug 22 '23 at 04:43
7

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
zumafra
  • 1,255
  • 2
  • 13
  • 19
6

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:

  • npmv for the version of npm, for example, NPM version is: 4.2.0
  • npmv <package-name> for the local version, for example, 0.8.08
  • npmv <package-name> g for global version, for example, 0.8.09
  • npmv <package-name> 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JGFMK
  • 8,425
  • 4
  • 58
  • 92
5

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>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Aymen Jarouih
  • 469
  • 5
  • 8
4

Access the package.json file

You can access the package.json or bower.json file of the package with:

Windows (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.

Mac/Linux:

cat node_modules/prettier/package.json | grep version

This will output something like this:

screenshot of command output

Aakash
  • 21,375
  • 7
  • 100
  • 81
  • 8
    Not only are there much easier ways to do this, the version you have specified in your package.json may not actually be the installed version due to semver range notations. That is, a dependency may be specified as version ^1.3.0, but that can mean anything from version 1.3.0 to 1.99.99 – Isochronous Jun 14 '17 at 14:29
  • On [Windows](https://en.wikipedia.org/wiki/Microsoft_Windows) only, presumably? What version / edition was this tried on? Please respond by [editing (changing) your answer](https://stackoverflow.com/posts/40653641/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Aug 11 '22 at 19:38
  • Hi @PeterMortensen, I've update the answer with few more details. Hope this helps!! – Aakash Aug 12 '22 at 07:34
4

I am using

npm list --depth=0 | grep module_name@

It brings me results like this:

module_name@2.1033.0
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
1nstinct
  • 1,745
  • 1
  • 26
  • 30
3

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
psergiocf
  • 1,493
  • 2
  • 20
  • 27
  • 24
    All of those show the newest available version, not the currently installed version – sth Sep 05 '16 at 17:21
3

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.

Aliaksei
  • 1,094
  • 11
  • 20
3

We can use

npm info (your module name) version

Nitin .
  • 808
  • 9
  • 12
3

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
joliver
  • 131
  • 1
  • 8
saltedlolly
  • 105
  • 1
  • 3
0

Another way to find specific node module's version is to find its package.json in node_modules folder and find there "version" value. Not in whole application's package.json but in module's own package.json.
For example one need to know the version of package foo installed. Then the foo folder should be opened in node_modules. It will be package.json inside foo folder. Then this package.json should be opened i.g. in notepad. Then find "version" value in it.

pav
  • 61
  • 6
-1

npm list npm list 'package name' npm show 'package name' version

-2

There is a simple way of doing this. First, go to the desired location (where the package.json is located). And simply open package.json file as a text editor.

By this method, you can find all module versions in one place.

package.json looks like this

{
  "name": "raj",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcrypt": "^5.0.1",
    "connect-flash": "^0.1.1",
    "dotenv": "^10.0.0",
    "ejs": "^3.1.6",
    "express": "^4.17.1",
    "express-session": "^1.17.2",
    "mysql2": "^2.2.5",
    "passport": "^0.4.1",
    "passport-local": "^1.0.0",
    "sequelize": "^6.6.2",
    "socket.io": "^4.1.2"
  }
}

So thus you can read every installed dependency (modules) in your pc, i.e., "socket.io": "^4.1.2", so 'socket.io' has version 4.1.2.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Raj Gohil
  • 209
  • 3
  • 6
-3

You can also view the package.json file manually in a text editor to see what packages are dependencies. Use this if npm list isn't working as a manual alternative.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
-7

Just check your package.json file.

"dependencies": {
  "ajv": "^8.9.0",
  "ajv-keywords": "^5.1.0",
  "fastify": "^3.27.0"
yılmaz
  • 365
  • 1
  • 14
  • 1
    This only shows the version requirements, not the version itself. For example, while the version requirement is "ajv-keywords": "^5.1.0", the actual installed version of the package could be v5.39.104. – floodlitworld Apr 07 '22 at 02:05
  • @floodlitworld you can check node-modules directory for that info – yılmaz Apr 08 '22 at 21:49