Putting your code up on GitHub is helpful, but publishing your library to npm makes it even easier for people to use your library. In this lesson, you'll learn how to publish your library and validate that it published correctly.
Now we're finally ready to publish our node module. We've already configured everything locally with NPM in a previous lesson, as well as in our package JSON with this metadata. All that really needs to happen is to simply run npm publish. This will go out to NPM, register our module in the registry, and then create the starwars-names module.
Now we can run npm info starwars-names. You'll notice this looks similar to our package JSON. This allows us to install our 1.0.0 version.
Let's go ahead and test this out a little bit. Let's just change our directory to the desktop, and then we'll run npm install starwars-names. This will install our module and our module's dependencies.
Now, we can create a file that uses our Star Wars names, so we'll say vim index.js, and we'll insert a starwars-names require starwars-names, and then we'll console.log starwars-names.all. Then we'll console.log starwars-names.random, and we'll do that a few times.
Now if we say node index.js, we get all those printed, and then our random items printed as well. If we run it again, the random ones are different every time. So it looks like we successfully published our first package to NPM. If we go to the NPM registry, we can shortcut to our module name with npm.im/starwars-names, and this will take us to our registry item.
Here we have starwars-names, get random Star Wars names. Our readme could use a little bit of help, but it has a link to our starwars-names. It has our license here. It lists me as a collaborator, and other information about our module, such as our dependencies. That is publishing your first module to NPM.
In review, all that you need to do is run npm publish. As long as you've configured your NPM with your user, then you should be all set.