ThomasReggi
ThomasReggi

Reputation: 59355

Get the latest npm package version programatically?

Looking for a way to access the latest version number of an npm package. Is there some kind of API where I can't ping npm directly? Or is there a programatic npm command I can use?

getNpmVersion('lodash').then(console.log) // => 4.11.1

Upvotes: 0

Views: 235

Answers (2)

Josh Wulf
Josh Wulf

Reputation: 4877

Also:

npm view {packagename} version

Upvotes: -2

ThomasReggi
ThomasReggi

Reputation: 59355

Found a module called npm-latest that does exactly this:

import npmLatest from 'npm-latest'
import Promise from 'bluebird'
const npmLatestAsync = Promise.promisify(npmLatest)
async function getNpmVersion (dep) {
  let { name, version } = await npmLatestAsync(dep)
  return { name, version}
}

Upvotes: 3

Related Questions