npm - how to show the latest version of a package

node.jsNpmVersioning

node.js Problem Overview


How do I use npm to show the latest version of a module? I am expecting something like npm --latest express to print out v3.0.0.

node.js Solutions


Solution 1 - node.js

You can use:

npm show {pkg} version

(so npm show express version will return now 3.0.0rc3).

Solution 2 - node.js

If you're looking for the current and the latest versions of all your installed packages, you can also use:

npm outdated

Solution 3 - node.js

As of October 2014:

npm view illustration

For latest remote version:

npm view <module_name> version  

Note, version is singular.

If you'd like to see all available (remote) versions, then do:

npm view <module_name> versions

Note, versions is plural. This will give you the full listing of versions to choose from.

To get the version you actually have locally you could use:

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

Note, even with package.json declaring your versions, the installed version might actually differ slightly - for instance if tilda was used in the version declaration

Should work across NPM versions 1.3.x, 1.4.x, 2.x and 3.x

Solution 4 - node.js

You can see all the version of a module with npm view. eg: To list all versions of bootstrap including beta.

npm view bootstrap versions

But if the version list is very big it will truncate. An --json option will print all version including beta versions as well.

npm view bootstrap versions --json

If you want to list only the stable versions not the beta then use singular version

npm view bootstrap@* versions

Or

npm view bootstrap@* versions --json

And, if you want to see only latest version then here you go.

npm view bootstrap version

Solution 5 - node.js

The npm view <pkg> version prints the last version by release date. That might very well be an hotfix release for a older stable branch at times.

The solution is to list all versions and fetch the last one by version number

$ npm view <pkg> versions --json | jq -r '.[-1]'

Or with awk instead of jq:

$ npm view <pkg> --json  | awk '/"$/{print gensub("[ \"]", "", "G")}'

Solution 6 - node.js

There is also another easy way to check the latest version without going to NPM if you are using VS Code.

> In package.json file check for the module you want to know the latest > version. Remove the current version already present there and do CTRL > + space or CMD + space(mac).The VS code will show the latest versions

image shows the latest versions of modules in vscode

Solution 7 - node.js

This npm-check-updates package will help you to update and check the latest available package.

  • $ ncu Checking package.json
  • $ ncu -u Update all packages.
  • $ ncu -g Check global packages.

For more details check this link

https://www.npmjs.com/package/npm-check-updates

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
QuestionTrantor LiuView Question on Stackoverflow
Solution 1 - node.jsCD..View Answer on Stackoverflow
Solution 2 - node.jsadiusView Answer on Stackoverflow
Solution 3 - node.jsarcseldonView Answer on Stackoverflow
Solution 4 - node.jsRajkeshwar PrasadView Answer on Stackoverflow
Solution 5 - node.jsAndrea RattoView Answer on Stackoverflow
Solution 6 - node.jsSksaif UddinView Answer on Stackoverflow
Solution 7 - node.jsGeorge JohnView Answer on Stackoverflow