Download a package from npm as a tar (not installing it to a module)


Npm Problem Overview

Is there some URL from which I can download a given package from npm (as a tarball or something)? I need the exact files that were originally uploaded to npm.

Using npm install gets a different, generated package.json for example. I want the exact original set of files that was published.

Npm Solutions

Solution 1 - Npm

You can use npm view to get the URL to the registry's tarball (in this example for the module level):

$ npm view level dist.tarball

And to download tarball, you can use npm pack:

$ npm pack level

Solution 2 - Npm

Just run the command

npm view [package name] dist.tarball

It will return a tar url.

Solution 3 - Npm

Running npm pack PACKAGE_NAME will download a tarball of any package on npm.

To extract it, just run tar -xzf DOWNLOADED_FILE.tgz

npm pack react

then extract:

tar -xzf react-16.6.3.tgz

Solution 4 - Npm

If you need to get the tarball without having npm installed, you can fetch the package information using curl and use jq to get the right information from the JSON:

curl \
    | jq '.versions[."dist-tags".latest].dist.tarball'

This is for instance useful if you're building a Docker container that requires one npm package, and don't want to install npm just for that.

Solution 5 - Npm

Yes, you can npm install <git remote URL> to download the full repository into node_modules. This will be directly from the repository's host, rather than via npm, though. See the npm install docs for more information.


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncallumView Question on Stackoverflow
Solution 1 - NpmKenanView Answer on Stackoverflow
Solution 2 - NpmAman JainView Answer on Stackoverflow
Solution 3 - NpmZanderView Answer on Stackoverflow
Solution 4 - Npmuser1544337View Answer on Stackoverflow
Solution 5 - NpmDerek PetersonView Answer on Stackoverflow