Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Publish a Module to the NPM Registry


    This lesson shows you how to:

    • create a user account on the npm registry
    • publish your module to the registry
    • use npm version to bump the version number of your package
    • publish updated versions of your module to the registry
    • unpublish modules from the registry


    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    The first thing we need to do is create our user on the npm registry, so we'll do npm add user. I'm going to specify my username, a password, and then my email address. If you'd like to confirm that your user account's been created, you can go to and then the username that you selected.

    There are actually two requirements to publish a package to the npm registry. If we take a look inside of our package.json file, the first requirement is that the package has a name. The second is that it has a version number.

    So we've met both of those requirements, so we're ready to publish. We'll publish our module with the npm publish command, and if we want to verify that it was published we can go back to the website, reload the page, and you can see under my profile here that say hello world version 1.0has been uploaded.

    This also means that people are able to download it from the registry and install your package using npm install and the name of your package. Say hello world version 1.0was installed.

    If we make a change to our package, we can change this to say hello world from the npm registry. If we want to publish those changes to the npm registry, we get an error, because you can't overwrite the previously published version, which is why the version number is a required field.

    We can run npm version patch, and that's going to bump our version from 1.00to 1.01. With the npm version command you can supply patch, minor, and major as arguments, and it will bump the appropriate version number. Now let's try to publish that again, and we get confirmation that say hello world version 1.01 has been published.

    If we run our npm install command again over here, you can see the updated version was installed. Then finally we can look on the npm registry site itself, refresh that page, and you can see that say hello world version 1.01 is live in the registry.

    The last thing we want to do is clean this package out of the npm registry because it really serves no purpose and doesn't add any value to it. We can do an npm unpublish say hello world.

    You're going to notice here that because we have different versions of it, it's going to request that we unpublish it version by version. Or, in this case, because we know that there's nothing out there in the wild that's using this for dependencies, we can actually just do npm unpublish say hello world with the --force flag, and it'll remove it from the registry forcibly.