Lesson 28 / 28

Publishing to npm

The conceptual steps to share a package with the world.

What publish needs

A unique name, a version, an npm login, and a bin field if it's a CLI tool — then npm publish uploads it to the registry.

publish workflow

Bump the version before every publish — npm rejects re-publishing the same version number.

npm login
npm version patch      # 1.0.0 -> 1.0.1
npm publish

Quick check: Why does npm version patch matter before publishing an update?

  • It compiles the code
  • npm refuses to publish a version number that already exists on the registry
  • It deletes the previous version
Answer

npm refuses to publish a version number that already exists on the registry — The registry treats each version as immutable — you must bump the number to publish new changes.