# Publishing to npm — Node.js

Source: https://www.geekswithgeeks.com/en/nodejs/node-npm-publish

> 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.

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

**Quiz:** Why does npm version patch matter before publishing an update?

- [ ] It compiles the code
- [x] 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.
