admin管理员组文章数量:1415139
I'd like my node package (published on npm) to alert the user when a new version is available. How can i check programmatically for the latest version of a published package and pare it to the current one?
Thanks
I'd like my node package (published on npm) to alert the user when a new version is available. How can i check programmatically for the latest version of a published package and pare it to the current one?
Thanks
Share Improve this question asked Jun 22, 2017 at 12:35 pistacchiopistacchio 59k110 gold badges287 silver badges434 bronze badges 1- 1 I think you can find what you want in this npm package : npmjs./package/npm-check-updates Check how he doing this for his project. – Zagonine Commented Jun 22, 2017 at 12:38
1 Answer
Reset to default 8You can bine the npmview
(for getting remote version) and semver
(for paring versions) packages to do this:
const npmview = require('npmview');
const semver = require('semver');
// get local package name and version from package.json (or wherever)
const pkgName = require('./package.json').name;
const pkgVersion = require('./package.json').version;
// get latest version on npm
npmview(pkgName, function(err, version, moduleInfo) {
// pare to local version
if(semver.gt(version, pkgVersion)) {
// remote version on npm is newer than current version
}
});
本文标签: javascriptNode check latest version of package programmaticallyStack Overflow
版权声明:本文标题:javascript - Node: check latest version of package programmatically - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745216871a2648211.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论