Publish a Module to the NPM Registry

Will Button
InstructorWill Button
Share this video with your friends

Social Share Links

Send Tweet
Published 9 years ago
Updated 5 years ago

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

[00:00] 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 npmjs.com/~ and then the username that you selected.

[00:30] 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.

[00:45] 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 npmjs.com website, reload the page, and you can see under my profile here that say hello world version 1.0has been uploaded.

[01:07] 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.

[01:23] 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.

[01:49] 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.

[02:19] 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.

[02:36] 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.

[02:52] 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.

egghead
egghead
~ 13 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today