Download source from npm without installing it

How can I download the source code of a package from npm without actually installing it (i.e. without using npm install thepackage)?


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)

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


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.


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