简体   繁体   English

以编程方式获取最新的npm软件包版本?

[英]Get the latest npm package version programatically?

Looking for a way to access the latest version number of an npm package. 寻找一种方法来访问npm软件包的最新版本号。 Is there some kind of API where I can't ping npm directly? 是否存在无法直接ping npm的API? Or is there a programatic npm command I can use? 还是我可以使用程式化的npm命令?

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

Found a module called npm-latest that does exactly this: 找到了一个名为npm-latest的模块,该模块正是这样做的:

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

也:

npm view {packagename} version

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM