TL;DR
This post outlines how to inspect the registry information of an NPM package using the npm view
command, download an NPM package directly from a registry using the npm pack
command, and extract the contents of the package tarball.
Inspect an NPM package’s contents before downloading
npm
CLI version used at the time of writing this post was 5.5.1
.
npm view
The npm view
command can be used to directly view registry information about a package without the need to download or install the package. We’re using the lodash package as an example.
$ npm view lodash
{ name: 'lodash',
description: 'Lodash modular utilities.',
'dist-tags': { latest: '4.17.4' },
versions:
...
}
NOTE: The default version is “latest” if omitted from the npm view
command.
Query package metadata
The npm view
command can also query package metadata on the registry and return detailed information on a specific package.
For example, to see all the versions available for a package, pass versions
as an option to the npm view lodash
command:
$ npm view lodash versions
[ '0.1.0',
'0.2.0',
'0.2.1',
...
'4.17.1',
'4.17.2',
'4.17.3',
'4.17.4' ]
Or get the tarball URL:
$ npm view lodash dist.tarball
https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz
To see all the available options for the npm view
command, visit the CLI page on NPM’s website.
Download an NPM package
Download the package tarball directly from the public NPM registry using the npm pack
command. We’re using the lodash package as an example.
$ npm pack lodash
lodash-4.17.4.tgz
NOTE: The default version is “latest” if omitted from the npm pack
command.