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
Add a ment  | 

1 Answer 1

Reset to default 8

You 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