Publishing a package in NPM registry


In this post, we are going to learn how to publish a package into the NPM registry.

Steps to create a package are

  • Create a new node application in your desktop
 //Create a package.json file in the application
   $ npm init


 //Add functionality in your application which you need to publish in NPM registry.

 //Command is used to create an account in NPM
   $ npm adduser
 
 //If you already have an account instead of adduser command run 
   $ npm login

  //It will ask username, password, and email to authenticate the user.

  //In order to publish this package run  
    $ npm publish

** Note**: The package name should be unique it should not be available in NPM registry

Once we publish the package your package will be publicly available and anyone can use your package by installing that package in their node application.

Steps to update a package

once we change the functionality in our package and we need to update this to the registry

  // Update the version number of our package(Major, Minor, patch)
    $ npm update minor

 // If you successfully update the package with version number, In order to publish the package run

    $ npm publish

This update the package with a new version number.