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
}
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745216872a4617065.html
评论列表(0条)