publish
npm pack
Creates the tarball (`<name>-<version>.tgz`) exactly as `npm publish` would upload, without actually publishing. Perfect for previewing shipped files or for installing locally to test.
npm pack [<pkg>|<folder>] [--dry-run] Common flags
| Flag | Purpose |
|---|---|
| --dry-run | List the files that would be packed without writing the tarball |
| --json | Emit the file list and metadata as JSON |
| --pack-destination <dir> | Write the .tgz to a specific directory |
Examples
npm pack --dry-run Preview the exact file list that publish would send
npm pack Produce my-pkg-1.0.0.tgz in the current directory
npm install ./my-pkg-1.0.0.tgz Install the packed tarball locally to test it
Gotcha
The tarball respects the `files` field and .npmignore — always run `npm pack --dry-run` before publishing to catch accidentally-included secrets or oversized files. If `files` is missing, .gitignore is used as a fallback ignore.
Related commands
npm publish
Uploads the current package to the registry so it can be installed by others. Honors the `files` field, `.npmignore`, and .gitignore to decide which files ship.
npm version
Bumps the version field in package.json (and package-lock.json), then creates a git commit and tag — all in one step. Runs preversion/version/postversion lifecycle scripts.
npm install
Installs a package (and its dependencies), adding it to package.json and refreshing package-lock.json. Without arguments, installs everything already declared in the current project's package.json.
npm unpublish
Removes a specific version — or the whole package — from the registry. Subject to strict rules: only within 72 hours of publish and only if nothing else depends on it.