1

Instead of installing the latest version of an NPM package using

npm install x@latest

is there a way to view the latest stable version? something like this:

npm view x@stable version

I am looking for a programmatic/command line solution.

https://docs.npmjs.com/cli/view

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • 1
    Possible duplicate of [Nodejs npm show latest version of a module](https://stackoverflow.com/questions/11949419/nodejs-npm-show-latest-version-of-a-module) –  Feb 22 '18 at 22:45
  • yeah I am looking for the latest *stable* version, if that's possible, not just the latest version – Alexander Mills Feb 22 '18 at 23:27
  • 1
    Ah right, my bad. –  Feb 22 '18 at 23:30
  • Possible duplicate of [How am I supposed to find out what is the latest stable version of an npm package?](https://stackoverflow.com/questions/11220598/how-am-i-supposed-to-find-out-what-is-the-latest-stable-version-of-an-npm-packag) –  Feb 22 '18 at 23:31
  • yeah that solution is not a complete programmatic solution, although I am not sure if there is one. – Alexander Mills Feb 22 '18 at 23:38
  • 1
    I think there's a programmatic solution in one of my old repos, now that I think about it. If I find it, I'll write up an answer. –  Feb 23 '18 at 00:03
  • ok cool thx that would be good – Alexander Mills Feb 23 '18 at 00:57

1 Answers1

1

Utilizing the following syntax returns the semver/value of the latest stable version only:

npm view <name> dist-tags.latest

You'll need to replace the <name> part with the actual package name.

Example:

npm view babel-cli dist-tags.latest

Running the command above currently prints 6.26.0 to the console, whilst the latest non-stable version available is the npm registry is currently 7.0.0-beta.3


Notes:

The command above will report the same version which would get installed when running:

npm install <name>@latest

Caveat: For either of the two commands to get the truly stable latest version they are reliant on the author/owner of the package having correctly managed their dist-tags. An excerpt from the docs (at the link provided) reads:

Publishing a package sets the latest tag to the published version unless the --tag option is used. For example, npm publish --tag=beta.

RobC
  • 22,977
  • 20
  • 73
  • 80