Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including get-latest with all npm packages installed. Try it out:

var getLatest = require("get-latest")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

get-latest v0.1.0

Get the latest package.json for a module.

get-latest NPM version NPM downloads Build Status

Get the latest package.json for a module.

You might also be interested in get-pkg.

Install

Install with npm:

$ npm install --save get-latest

What does this module do?

This module will return the latest (or newest) package.json file for a specified module. The getLatest function requires the current package.json file to be able to compare versions and return the current package.json if the latest hasn't been downloaded yet.

The first use of get-latest will always return the current package.json because the latest has not been downloaded. Once the latest is downloaded and cached, then the latest version will be returned.

This is intended to be used by CLIs and applications that want to quickly check for the latest version without blocking execution, but still download the latest to be used during the next execution of the CLI or application.

Usage

var pkg = require('./package.json');
var getLatest = require('get-latest');
var latest = getLatest(pkg);
console.log('current', pkg.version);
console.log('latest', latest.version);
//=> 'current 0.1.0'
//=> 'latest' 0.2.0'

API

getLatest

Get the latest package.json for the specified package.json and given options.

This library will use the given package.json to determine if it's the latest one or if there is a newer version. If the given package.json is the latest, then it is returned.

Params

  • pkg {Object}: Current package.json to use for checking for the latest.
  • options {Object}: Additional options to control how the checking is handled.
  • options.timespan {String}: String used to determine if the background process should be started to npm for the latest version. Defaults to '1 hour ago'.
  • options.cache {Boolean}: Set to false to ensure that the background process is always started.
  • returns {Object}: Latest package.json is returned.

Example

var latest = getLatest(require('./package.json'));

About

Related projects

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Please read the contributing guide for avice on opening issues, pull requests, and coding standards.

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Brian Woodward

License

Copyright © 2016, Brian Woodward. Released under the MIT license.


This file was generated by verb, v0.9.0, on August 17, 2016.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free