Publishing a package to npm
Publish TaskKit to the npm registry under your scope, so one command installs it anywhere, and release fixes with npm version and semantic versioning.
Publish TaskKit to the npm registry under your scope, so one command installs it anywhere, and release fixes with npm version and semantic versioning.
Tested with TypeScript 7.x · Node.js LTS
In the last lesson TaskKit became a package, and the tarball you
installed worked in any folder on your computer. Your friend could not
have used that file, though: it lived on your disk. She needs TaskKit
on the registry of npm (Node package manager), where npm install
looks, and she needs every fix you make after that to reach her too.
In this lesson you merge the work of the last lesson, make an npm account, and
publish TaskKit, so that npm install -g @ana/taskkit (-g for global, as
in the last lesson) is all she types. Then you release a fix the way packages
do: with a new version number that tells her what changed.
Publishing goes from main, so the branch of the last lesson goes
through a pull request first, with gh, the GitHub command-line tool
of lesson A2.1:
git add .
git commit -m "Get TaskKit ready for npm"
git push -u origin publish
gh pr create --fillOnce its checks have their tick, merge it with
gh pr merge --merge --delete-branch.
npm publish then packs the folder again, running prepack first,
asks the registry whether this version is new, and only then sends
the tarball. Press Next step to follow a release, or let it play, and
switch between a new version and one already published:
All 5 steps shown.
All 3 steps shown.
Publishing needs an account on npmjs.com. The names below are npm's on 26 November 2026, and its pages may change. Go to npmjs.com/signup, fill in Username (lower case; it becomes your scope), Email address and Password, agree to the terms, and click Create An Account. npm then sends you an email: verify your address, because an account whose email is not verified cannot publish.
npm also requires two-factor authentication, 2FA, to publish: a second proof that it is you, besides the password, such as your fingerprint or face (Touch ID, Windows Hello) or a security key. So npm's documentation said on 26 November 2026; the rules may change. Turn it on as npm's page Configuring two-factor authentication describes.
Then connect your terminal to the account:
npm loginnpm notice Log in on https://registry.npmjs.org/
Login at:
https://www.npmjs.com/login?next=/login/cli/…npm offers to open the address in your browser when you press
Enter (on a Mac the key says return); sign in
there, and the terminal says it is done. npm whoami prints the
username you are logged in as, which is your scope. A login does not
last: on 26 November 2026 a session from npm login lasted two hours
(GitHub's npm changelog of 9 December 2025; this may change), so you
log in again before a later publish.
Publish from main, with the merged pull request in it:
git switch main
git pullThen ask npm to do everything except the upload: --dry-run packs,
checks and prints, and sends nothing.
npm publish --dry-runnpm notice total files: 17
npm notice
npm notice Publishing to https://registry.npmjs.org/ with tag latest and public access (dry-run)
+ @ana/taskkit@1.0.0with tag latest means this version becomes the one npm install
picks when nobody names a version; latest is npm's own label, not
the Git tag you meet below. public access is your publishConfig:
if the line says default access instead, the field is missing. Now
the real thing:
npm publishnpm asks you to confirm with your second factor (it may open your
browser), uploads, and ends like the dry run without (dry-run):
+ @ana/taskkit@1.0.0 means the registry has it. TaskKit's page,
npmjs., shows the README you packed.
On her laptop, in any folder, npm install -g @ana/taskkit prints the
same added 19 packages as your test install, and taskkit works for
her as it did for you. Someone who only wants to try it can skip the
install: npx @ana/taskkit add "Call the bank" downloads the package
into npm's cache, a folder where npm keeps what it downloaded, and
runs its command once. The first time, npx asks Ok to proceed?;
press Enter to say yes.
A week later you correct a message, and she should get it. The registry never
takes a version twice: once @ana/taskkit@1.0.0 is published, that name and
number can never point at other files, even if you remove the package (npm's
unpublish policy on its docs, checked on 26 November 2026). The common mistake
below shows what npm says when you try. So every release gets a new number,
and which number you raise tells everyone what changed. This is semantic
versioning, the rule behind the caret of lesson 9.2: ^1.0.0 takes any
1.x.x, because only the first number rises when old code may stop working.
A fix; nothing else
npm version patch, after a wrong message is corrected.
Something new; nothing gone
npm version minor, after a list command is added.
Something that worked may not
npm version major, after remind is removed.
Raising a number sets the ones after it to 0: a major release after
1.4.2 is 2.0.0.
The fix goes through a branch and a pull request, as every change
does, and so does its new version: lesson A2.5's ruleset turns away a
push straight to main. Make the branch with
git switch -c fix-summary (-c for create), commit the fix on
it, and then:
npm version patchv1.0.1npm version patch raised the number in package.json and
package-lock.json, committed both, and gave the commit a tag, a
name Git keeps for one commit: git log --oneline now starts with a
commit named 1.0.1, and git tag lists v1.0.1. It refuses to
start while a file Git tracks has changes you have not committed, with
npm error Git working directory not clean. Commit first.
Push the branch with its tag and open the pull request:
git push -u origin fix-summary --follow-tags
gh pr create --fill-u links the branch to GitHub's copy, as in lesson A2.1.
--follow-tags pushes the tag with the commits, so GitHub shows which
commit each version was; a plain git push leaves tags behind. Once
the checks have their tick, merge it, and publish from main:
gh pr merge --merge --delete-branch
git switch main
git pull
npm login
npm publishnpm publish runs prepack, so the check and the build run again on
the new version, and ends with + @ana/taskkit@1.0.1. Her next
npm install -g @ana/taskkit gets 1.0.1, and her list stays where it
was, in her home folder.
TaskKit is at 1.0.1. You add a list command, commit it, and run
the command below.
Predict
What does npm version minor print?
npm version minorAfter a fix, it is easy to run npm publish straight away, before the
number changes.
Common mistake
A fix published without a new version
You correct a message, commit it, and publish, with package.json
still at 1.0.0:
npm publishnpm error You cannot publish over the previously published versions: 1.0.0.npm asks the registry about the version before it uploads anything, so nothing was sent and her copy is unchanged.
npm error You cannot publish over the previously published versions: 1.0.0.
The fix
Give the fix its number the way "A new version" does: on the fix's
branch, npm version patch, then push with --follow-tags, merge,
pull main, and publish from there, with npm login first if your
last one was more than two hours ago. npm publish then ends with
+ @ana/taskkit@1.0.1.
A version number names one set of files forever. When npm publish
refuses, the question is never how to force it, only which number the
change deserves.
Pass all three tasks to complete the lesson with practice. Reach the end without them and it counts as read only.
This page cannot publish a package, so one exercise writes the
commands as console.log lines, and two ask what npm does with
versions and settings.
Which number goes up
TaskKit is at 1.1.0. You rename the --due option to --by, so
taskkit add --due … no longer works. Which command makes the next
version?
Release a fix
This program prints the commands that release TaskKit's fixed message from its
branch, in an order that fails. The merge and the pull of main before the
publish are left out here, to keep the list short. Change the order of the
lines, without changing any line itself, so each command works: the fix is
committed before npm version starts, the tag goes up with the branch, and
only a new version is published.
Loading the editor…
A scope's first publish
A friend publishes @her/notes for the first time, and the last
npm notice line of npm publish --dry-run ends with
with tag latest and default access (dry-run). What does
default access tell her?
Recap · 3 questions
Check yourself
You removed 1.0.0. Can you publish 1.0.0 again?
Check yourself
What does npm publish --dry-run do?
Check yourself
Why push with --follow-tags?
0 of 0 answered.
Cheat sheet
Publishing a package to npm
What things are
| Word | What it means |
|---|---|
| Registry | Where packages are published and installed from |
| 2FA | A second proof it is you; npm needs it to publish |
| Semantic versioning | Major.minor.patch: what changed, by which number |
| Tag | A name Git keeps for one commit: v1.0.1 |
Commands
| Write | To |
|---|---|
npm login | Connect the terminal to your npm account |
npm whoami | Print the username you are logged in as |
npm publish --dry-run | Do everything but the upload |
npm publish | Send the package to the registry |
npx @ana/taskkit | Run a package's command without installing it |
npm version patch | Raise the version, commit it and tag it |
git push --follow-tags | Push the commits and their tags |
Rules
| Rule | What it means |
|---|---|
Publish from main | After the pull request is merged |
| A version is used once | A fix needs a new number |
| Patch, minor, major | A fix, something new, something that breaks |
You can now publish TaskKit to npm and release a new version with the right number, so every fix reaches whoever installed it.
That closes the tools of Bonus A. Next is Choosing a path: what to learn next for frontend, backend, or tooling, which takes the places TypeScript runs and the tools you met, and helps you pick where to go deeper.
Before you move on, make a patch release of your own: change one
message TaskKit prints on a branch, commit it, run npm version patch,
and before you push, run npm pack --dry-run and check that the
version and the list are what you expect.