Socket
Socket
Sign inDemoInstall

latest

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

latest - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

31

index.js

@@ -1,3 +0,7 @@

var npm = require('npm');
var npm = require('npm'),
util = require('util');
/**
* get the latest version of a package
*/
module.exports = function(name, cb) {

@@ -15,1 +19,26 @@ npm.load({name: name}, function(err) {

};
/**
* Convenience method
*
* Given a package.json style obj, determine if there are updates available
*
* Optionally, give true as a second argument to exit after writing the message
*/
module.exports.check_update = function (package, cb) {
module.exports(package.name, function(err, v) {
var s, ret = 0;
if (err) {
s = ">>> Couldn't determine latest version";
ret = 2;
} else if (v !== package.version) {
s = util.format('>>> You are running version %s, a newer version %s is available\n', package.version, v);
s += util.format('>>> Consider updating with: npm update -g %s', package.name);
ret = 1;
} else {
s = util.format('You are running the latest version %s', package.version);
ret = 0;
}
cb(ret, s);
});
};

4

package.json
{
"name": "latest",
"description": "Quickly determine the latest available version of a package in NPM",
"version": "0.0.0",
"description": "Determine the latest available version of a package in npm",
"version": "0.0.1",
"author": "Dave Eddy <dave@daveeddy.com> (http://www.daveeddy.com)",

@@ -6,0 +6,0 @@ "contributors": [],

@@ -6,3 +6,3 @@ latest

Useful for command line tools that want to check for upgrades available
Useful for command line tools that want to check for available upgrades

@@ -12,3 +12,3 @@ Example

Get the latest version of `autocast`
Get the latest version number of `autocast`

@@ -41,4 +41,6 @@ ``` js

Check for upgrades!
### Convenience Function
Check for upgrades in an app
``` js

@@ -48,14 +50,15 @@ var latest = require('latest'),

latest(p.name, function(err, v) {
if (err) {
console.warn("Couldn't determine latest version");
} else if (v !== p.version) {
console.warn('You are running version %s, a newer version %s is available', p.version, v);
console.warn('Consider updating with: npm update %s', p.name);
} else {
console.log('You are running the latest version!');
}
latest.check_update(p, function(ret, message) {
console.log(message);
process.exit(ret);
});
```
#### check\_update(package-json-obj, cb(ret, message))
A convenience method that will check for newer versions of a module in npm given a
`package.json` object as the first argument.
The callback fires with a return code suitable for exiting with, and a message to print
Install

@@ -62,0 +65,0 @@ ------

var latest = require('../'),
p = require('../package.json');
latest(p.name, function(err, v) {
if (err) {
console.warn("Couldn't determine latest version");
} else if (v !== p.version) {
console.warn('You are running version %s, a newer version %s is available', p.version, v);
console.warn('Consider updating with: npm update %s', p.name);
} else {
console.log('You are running the latest version!');
}
latest.check_update(p, function(ret, msg) {
console.log(msg);
process.exit(ret);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc