logo hsb.horse
← Back to snippets index

Snippets

Download tarball from npm

How to download npm package tarballs (.tgz) using npm pack and pnpm info. Methods for npm, yarn, and pnpm.

Published: Updated:

There are times when you want to download an npm package tarball (.tgz file) directly. For offline installations or when you need to inspect package contents.

npm

Terminal window
npm pack <package-name>
# Example: download react tarball
npm pack react
# react-18.3.1.tgz is generated

The tarball is downloaded to the current directory.

yarn

You can also use npm pack with yarn:

Terminal window
npm pack <package-name>
# Example
npm pack react

Note that yarn pack serves a different purpose (packaging your own package into a tarball).

pnpm

Get the URL from the dist.tarball field:

Terminal window
pnpm info <package-name> dist.tarball
# Example
pnpm info react dist.tarball
# https://registry.npmjs.org/react/-/react-18.3.1.tgz

Once you have the URL, download it with curl or similar:

Terminal window
curl -O https://registry.npmjs.org/react/-/react-18.3.1.tgz

Extracting the tarball

Downloaded tarballs can be extracted with the tar command:

Terminal window
tar -xzf react-18.3.1.tgz
# package/ directory is generated
cd package/

What is a tarball?

npm packages are converted to tarballs (gzip-compressed tar archives) during npm publish and uploaded to the registry. When you run npm install, it downloads and extracts this tarball.

Downloading tarballs directly enables:

  • Package distribution in offline environments
  • Pre-inspection of package contents
  • Backup of specific versions