npm publish Explained

What npm publish does, with an example.

Published November 10, 2026

npm publish uploads your package to the npm registry so others can install it. The name and version must be unique, and the package is public unless scoped as private.

How it works

Control published files with the 'files' field or .npmignore. Bump the version with npm version first.

Use npm pack to preview the tarball.

Try it

npm publish --access public
+ @me/utils@1.0.0

Practical examples

Dry run

npm pack --dry-run

Publish a scoped package

npm login
npm publish --access public

Pre-release tag

npm version prerelease --preid=beta
npm publish --tag beta

Limit files

{ "files": ["dist"], "main": "dist/index.js" }

Common mistakes

  • Publishing secrets or .env files.
  • Forgetting to build before publishing.
  • Reusing versions (impossible after publish).

Key takeaways

  • npm publish uploads your package to the npm registry so others can install it.
  • Run npm help <command> for every option.
  • Commit package-lock.json.

FAQ

Can I unpublish?

Only within limited conditions; deprecate instead with npm deprecate.

Does this work with yarn or pnpm?

They have equivalents with similar commands.

More JavaScript articles