Publishing a node package

Publishing your node package to npm registry is a pretty easy task. To publish to npm registry you should have valid user credentials. You either create your user at link or you can create a user using following commands:

   λ npm adduser
   Username: User12345
    npm WARN Name must be lowercase
    Username: user_test
    Password: *******
    Email: (this IS public)
    Logged in as user_test on

If you already have a user then you can simply use npm login command to login to to npm registry. Once you are logged in, run the command npm whoami command to confirm that you are logged in.

Publishing a package

You can publish any folder which has a valid package.json file. To publish cd to the directory which has package.json file and then type  npm publish command.

Note: Your package name must be a unique, so ensure that it is not in use by someone else. To confirm this go to: where mypackage is the name your package.

If while publishing you get following error then most likely the package already exists in the npm repository:

npm ERR! you do not have permission to publish "my-package". 
Are you logged in as the correct user? : my-package

if the publish is successful then you should see following:


Publish successful!

Now switch over to the browser and browse to and search for your package to see if it is now visible in npm registry:


Your published package found in search

And voila !

Updating package

Since you’d also like to keep adding functionality to your packages and therefore would also like the update the package in the npm registry as well. For this you would need to do following:

  1. npm version <major|minor|patch>, this will ensure that your version in package.json is incremented.
  2. npm publish

When both the commands are successful then you can see your changes are updated in the npm registry.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s