https://github.com/vweevers/packument
Fetch package metadata from the npm registry
https://github.com/vweevers/packument
npm npm-registry packument
Last synced: 9 months ago
JSON representation
Fetch package metadata from the npm registry
- Host: GitHub
- URL: https://github.com/vweevers/packument
- Owner: vweevers
- License: mit
- Created: 2018-04-28T13:05:08.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-06-01T07:57:30.000Z (about 3 years ago)
- Last Synced: 2025-09-02T04:02:31.926Z (9 months ago)
- Topics: npm, npm-registry, packument
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# packument
**Fetch package metadata from the npm registry. Supports scopes and private registries. If you only need the metadata of a specific version, use [`packument-package`](https://www.npmjs.org/package/packument-package).**
[](https://www.npmjs.com/package/packument)
[](https://www.npmjs.com/package/packument)
[](https://github.com/vweevers/packument/actions/workflows/test.yml)
[](https://standardjs.com)
## example
```js
const packument = require('packument')
packument('levelup', (err, result) => {
if (err) throw err
console.log(result.versions['2.0.2'].dependencies)
})
```
## `packument(name[, opts], callback)`
Callback receives an error if any, a packument and response headers. Options:
- `headers`: custom headers (you can override any)
- `keepAlive`: shortcut for `headers: { connection: 'keep-alive' }`
- `full`: if true, fetch full metadata rather than an [abbreviated document](https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md).
## `packument = packument.factory(opts)`
Preconfigure the function. For example, to always fetch full metadata:
```js
const packument = require('packument').factory({ full: true })
packument('levelup', (err, result) => {
if (err) throw err
console.log(result._rev)
})
```
Combine it with an in-memory cache:
```js
const memoize = require('thunky-with-args')
const packument = memoize(require('packument').factory({ full: true }))
packument('levelup', (err, result) => {
// It will make only one request
})
packument('levelup', (err, result) => {
// Subsequent calls for the same package are cached
})
```
Reuse that cache in other modules:
```js
const memoize = require('thunky-with-args')
const packument = memoize(require('packument'))
const getPackage = require('packument-package').factory(packument)
getPackage('levelup', '~2.0.0', function (err, pkg) {
if (err) throw err
console.log(pkg.version)
})
```
## install
With [npm](https://npmjs.org) do:
```
npm install packument
```
## license
[MIT](http://opensource.org/licenses/MIT) © Vincent Weevers