Find the version of an installed npm package

node.jsPackageNpm

node.js Problem Overview


How to find the version of an installed node.js/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?

node.js Solutions


Solution 1 - node.js

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.

Solution 2 - node.js

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.

Solution 3 - node.js

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 node version: node -v

Solution 4 - node.js

npm info YOUR_PACKAGE version

e.g.

npm info grunt version
0.4.5

Solution 5 - node.js

From the root of the package do:

node -p "require('./package.json').version"

EDIT: (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>)

EDIT 2: updated as per answer from @jeff-dickey

Solution 6 - node.js

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>

Solution 7 - node.js

It's very simple.. Just type below line
npm view <package-name> version
Example
npm view redux version

I have version 7.2.0 of redux

Solution 8 - node.js

For local packages

npm list --depth=0

For Global packages

npm list  -g --depth=0

Solution 9 - node.js

Combining some of the above answers and produces a super simple and super quick lookup.
Run from project root. No need to cd into any folder, just 1 line:

node -p "require('SOMEPACKAGE/package.json').version"

Solution 10 - node.js

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
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
0.4.2

Solution 11 - node.js

You can also check the version with this command:

npm info <package name> version

Solution 12 - node.js

If you are brave enough (and have node 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.

Solution 13 - node.js

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

Solution 14 - node.js

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
`-- [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.

NPM documentation

Solution 15 - node.js

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

Solution 16 - node.js

Try with:

npm list --depth 1 --global packagename

Solution 17 - node.js

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

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 and two other copies in the node_modules of cli-table2 and karma.

It's really fast, and has some nice features like tab completion and match search.

Solution 18 - node.js

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 update, and unused version 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 version, new version update, and unused version.

enter image description here

It works globally too. give it a try. Hope this help someone.

Solution 19 - node.js

npm list package-name gives the currently installed version

Solution 20 - node.js

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/^.//'
0.4.5
  • the npm ll outputs a parseable string formatted like: /usr/lib/node_modules/npm:[email protected]:;
  • the grep command extracts the value between @ and :, inclusive;
  • the sed command removes the surrounding characters.

Solution 21 - node.js

This is simple question, and should have a simpler answer than what I see above.

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.

Solution 22 - node.js

You can see package.json to see installed packages version

To get the list on command line

npm ls

It will give you all installed packages in a project with their respective versions.

For particular package version

npm ls <package-name>

for eg

npm ls next

It will return version

-- next@10.1.3

Solution 23 - node.js

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

Solution 24 - node.js

I added this to my .bashrc

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 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 eg: NPM version is: 4.2.0
  • npmv <package-name> for the local version eg: 0.8.08
  • npmv <package-name> g for global version eg: 0.8.09
  • npmv <package-name> l for latest version eg: 0.8.10

Note -d on cut command means delimit by, followed by @, then f means field the 2 means second field since there will be one either side of the @ symbol.

Solution 25 - node.js

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.

Solution 26 - node.js

If you'd like to check for a particular module installed globally, on *nix systems use:

npm list -g --depth=0 | grep <module_name>

Solution 27 - node.js

Access the package.json

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

notepad ./node_modules/:packageName/package.json

This will open the package.json in notepad which has the version number of the :packageName you included in the command.

For example :

notepad ./node_modules/vue-template-compiler/package.json

Good Luck.

Solution 28 - node.js

We can use npm view any-promise(your module name) -v

Solution 29 - node.js

I am using

> npm list --depth=0 | grep module_name@

it brings me results like this

> ├── [email protected]

Solution 30 - node.js

To get ONLY the installed version number, try:

npm list -g --depth=0 packagename | grep packagename | cut -d'@' -f2

e.g. Installed version number of PM2:

npm list -g --depth=0 pm2 | grep pm2 | cut -d'@' -f2

Solution 31 - node.js

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

Solution 32 - node.js

There is a simple way of doing this. first, go to the desired location (where the package.json is located). and simple 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' having version 4.1.2

Solution 33 - node.js

npx runs commands in npm run-script-like shell environment, with all the usual environment variables available. Therefore you can also use something like

npx -c 'node -p "process.env.npm_package_version"'  

Solution 34 - node.js

Just check your package.json file.

"dependencies": {
  "ajv": "^8.9.0",
  "ajv-keywords": "^5.1.0",
  "fastify": "^3.27.0"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLaurent CouvidouView Question on Stackoverflow
Solution 1 - node.jsTheHippoView Answer on Stackoverflow
Solution 2 - node.jsPatrik AffentrangerView Answer on Stackoverflow
Solution 3 - node.jsSalvador DaliView Answer on Stackoverflow
Solution 4 - node.jsDavid BeckwithView Answer on Stackoverflow
Solution 5 - node.jsFergieView Answer on Stackoverflow
Solution 6 - node.jschrissavageView Answer on Stackoverflow
Solution 7 - node.jsDaksh PatelView Answer on Stackoverflow
Solution 8 - node.jsFarhan YaseenView Answer on Stackoverflow
Solution 9 - node.jsJoshuaDavidView Answer on Stackoverflow
Solution 10 - node.jsBenoit BlanchonView Answer on Stackoverflow
Solution 11 - node.jsSobin SunnyView Answer on Stackoverflow
Solution 12 - node.jsKundraLaciView Answer on Stackoverflow
Solution 13 - node.jsShekhar TyagiView Answer on Stackoverflow
Solution 14 - node.jsCharles OwenView Answer on Stackoverflow
Solution 15 - node.jskavigunView Answer on Stackoverflow
Solution 16 - node.jsEduardo CuomoView Answer on Stackoverflow
Solution 17 - node.jsRan YitzhakiView Answer on Stackoverflow
Solution 18 - node.jsMahendra PratapView Answer on Stackoverflow
Solution 19 - node.jsNandhiny DuraiView Answer on Stackoverflow
Solution 20 - node.jswjordanView Answer on Stackoverflow
Solution 21 - node.jszumafraView Answer on Stackoverflow
Solution 22 - node.jsSnowView Answer on Stackoverflow
Solution 23 - node.jspsergiocfView Answer on Stackoverflow
Solution 24 - node.jsJGFMKView Answer on Stackoverflow
Solution 25 - node.jsAliakseiView Answer on Stackoverflow
Solution 26 - node.jsAymen JarouihView Answer on Stackoverflow
Solution 27 - node.jsAakashView Answer on Stackoverflow
Solution 28 - node.jsNitin .View Answer on Stackoverflow
Solution 29 - node.js1nstinctView Answer on Stackoverflow
Solution 30 - node.jssaltedlollyView Answer on Stackoverflow
Solution 31 - node.jsSuperHarmony910View Answer on Stackoverflow
Solution 32 - node.jsRaj GohilView Answer on Stackoverflow
Solution 33 - node.jsPetr PlenkovView Answer on Stackoverflow
Solution 34 - node.jsyılmazView Answer on Stackoverflow