DevFox Labs
HomeCoursesRoadmapsChallengesToolsAboutContact

Bonus · A · Lesson A.14

intermediate38 minby DevFoxUpdated on 26 Nov 2026

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.

  • TypeScript
  • npm
Publishing a package to npm. Read this lesson at .

Previous lesson · A · A.13A package for npm: build TaskKit, describe it and try it Next lesson · A · A.15Choosing a path: what to learn next for frontend, backend, or tooling

On this page

  • From the tarball to the registry
  • Publish it
  • A new version
  • Predict before you run
  • The common mistake: the same version again
  • Exercises
  • Recap
  • A cheat sheet to keep
  • Where to go next
DevFox Labs

Structured lessons and courses for developers who care about craft.

Platform

HomeCoursesRoadmapsAll lessonsChallengesAboutContactRSS feed

Legal

Terms of ServicePrivacy PolicyCookie Policy

© 2026 DevFox Labs. All rights reserved.

    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.

    Goal of this lesson

    Publish TaskKit to npm, and release new versions with the right number.

    From the tarball to the registry

    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:

    bash
    git add .
    git commit -m "Get TaskKit ready for npm"
    git push -u origin publish
    gh pr create --fill

    Once 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:

    1. npm publish: reachedprepack: check, build
    2. The registry: passes✓Is this version new?
    3. npm install -g: reachedOn her computer
    4. taskkit: reachedRuns dist/index.js
    npm publish sends a new version to the registry; a version already there is refused
    All 5 steps shown.Step 1 of 5: npm publishStep 2 of 5: The registryStep 3 of 5: The registry: passesStep 4 of 5: npm install -gStep 5 of 5: taskkit

    All 5 steps shown.

    1. npm publish: reachedprepack: check, build
    2. The registry: stops here✕Is this version new?
    3. npm install -g: never reachedOn her computer
    4. taskkit: never reachedRuns dist/index.js

    The registry stops hereYou cannot publish over the previously published versions: 1.0.0.

    npm publish sends a new version to the registry; a version already there is refused
    All 3 steps shown.Step 1 of 3: npm publishStep 2 of 3: The registryStep 3 of 3: The registry: stops here. You cannot publish over the previously published versions: 1.0.0.

    All 3 steps shown.

    Publish it

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

    Then ask npm to do everything except the upload: --dry-run packs, checks and prints, and sends nothing.

    with 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 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.com/package/@ana/taskkit, 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 new version

    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.

    Patch: 1.0.1

    A fix; nothing else

    npm version patch, after a wrong message is corrected.

    Minor: 1.1.0

    Something new; nothing gone

    npm version minor, after a list command is added.

    Major: 2.0.0

    Something that worked may not

    npm version major, after remind is removed.

    The number you raise tells everyone what changed

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

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

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

    Predict before you run

    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?

    The common mistake: the same version again

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

    Practice

    1. 1
    2. 2
    3. 3

    Pass all three tasks to complete the lesson with practice. Reach the end without them and it counts as read only.

    Exercises

    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.

    Recap

    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.

    A cheat sheet to keep

    Cheat sheet

    Publishing a package to npm

    What things are

    WordWhat it means
    RegistryWhere packages are published and installed from
    2FAA second proof it is you; npm needs it to publish
    Semantic versioningMajor.minor.patch: what changed, by which number
    TagA name Git keeps for one commit: v1.0.1

    Commands

    WriteTo
    npm loginConnect the terminal to your npm account
    npm whoamiPrint the username you are logged in as
    npm publish --dry-runDo everything but the upload
    npm publishSend the package to the registry
    npx @ana/taskkitRun a package's command without installing it
    npm version patchRaise the version, commit it and tag it
    git push --follow-tagsPush the commits and their tags

    Rules

    RuleWhat it means
    Publish from mainAfter the pull request is merged
    A version is used onceA fix needs a new number
    Patch, minor, majorA fix, something new, something that breaks

    Where to go next

    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.

    Exercise · Read the code

    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?

    Exercise · Read the code

    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?

    Part of the outputtext
    npm notice Log in on https://registry.npmjs.org/
    Login at:
    https://www.npmjs.com/login?next=/login/cli/…
    The end of the outputtext
    npm 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.0
    Outputtext
    v1.0.1
    Part of the outputtext
    npm error You cannot publish over the previously published versions: 1.0.0.
    bash
    npm login
    bash
    git switch main
    git pull
    bash
    npm publish --dry-run
    bash
    npm publish
    bash
    npm version patch
    bash
    git push -u origin fix-summary --follow-tags
    gh pr create --fill
    bash
    gh pr merge --merge --delete-branch
    git switch main
    git pull
    npm login
    npm publish
    bash
    npm version minor
    bash
    npm publish
    Exercise · Fix the error

    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…