Download source from npm without installing it
Solution 1
You can use npm view [package name] dist.tarball
which will return the URL of the compressed package file.
Here's an example using wget
to download the tarball:
wget $(npm view lodash dist.tarball)
Solution 2
A simpler way to do this is npm pack <package_name>
. This will retrieve the tarball from the registry, place it in your npm cache, and put a copy in the current working directory. See https://docs.npmjs.com/cli/pack
Solution 3
If you haven't installed npm, with the current public API, you can also access the information about a package in the npm registry from the URL https://registry.npmjs.org/<package-name>/
.
Then you can navigate the JSON at versions > (version number) > dist > tarball
to get the URL of the code archive and download it.
Solution 4
npm pack XXX
is the quickest to type and it'll download an archive.
Alternatively:
npm v XXX dist.tarball | xargs curl | tar -xz
this command will also:
- Download the package with progress bar
- Extracts into a folder called
package
Solution 5
On linux I usually download the tarball of a package like this:
wget `npm v [package-name] dist.tarball`
Notice the backticks ``, on stackoverflow I cannot see them clearly.
"v" is just another alias for view:
AURIGADL
Updated on February 23, 2022Comments
-
AURIGADL about 2 years
How can I download the source code of a package from npm without actually installing it (i.e. without using
npm install thepackage
)? -
Ernst Robert about 8 yearsThis command gives you the direct link to the tarball. registry.npmjs.org/packagename/-/packagename-version.tgz
-
revelt over 4 years
npm pack <package's name>
is the shortest current way -
friederbluemle over 4 yearsPerfect. Also:
npm pack --dry-run <package_name>
will produce the same exact output, without placing thetgz
file in the current directory. -
Oliver Salzburg almost 4 yearsDownvoted because this doesn't use npm authentication information and results in 401 errors for private packages.
-
defvol about 3 yearsAdditionally, if you want to keep the same filename as the registry you could skip the last pipe as in:
npm v XXX dist.tarball | xargs curl -O
. In this case, curl -O will keep the filename from the npm registry, and since the file is already a tar.gz there's no need to pipe it again through the tar command. -
Codebling almost 3 yearsCaret-ish versions like
jquery@2
result in multiple URLs being returned