Fetch package metadata of a version from the npm registry. If you need metadata of all versions, use packument
.
const getPackage = require('packument-package')
// Defaults to latest
getPackage('levelup', function (err, pkg) {
if (err) throw err
console.log(pkg.version)
})
getPackage('levelup', '~2.0.0', function (err, pkg) {
if (err) throw err
console.log(pkg.version)
})
Callback receives an error if any, a package object and response headers. Options:
version
: either a dist tag (latest
), version (1.2.3
) or range (~1.2.3
).
Other options are passed to packument
.
Preconfigure the function. Useful for setting defaults or adding a cache:
const memoize = require('thunky-with-args')
const packument = memoize(require('packument').factory({ keepAlive: true }))
const getPackage = require('packument-package').factory(packument)
getPackage('levelup', '~2.0.2', (err, pkg) => {
// It will make only one request
})
getPackage('levelup', '^1.3.0', (err, pkg) => {
// Subsequent calls for the same package are cached
})
With npm do:
npm install packument-package
MIT © Vincent Weevers