How To Publish Your Package To NPM

Step by step guide to publishing your package to NPM

This article is a guide on how to publish your favourite package to npm.
Publishing an open-source project to npm allows other developers to use your works.

This is one step to contributing to open-source. Many of the open-source projects we use most of them are published NPM packages from (React, Vue and Angular).

Your project can also get appreciation from other fellow developers who will find your project helpful. On top of all these, other fellow developers will also be interested in contributing to your amazing project.

Does that feel cool to you? well, follow along this article to get started with publishing your packages to NPM.

Prerequisites

  • An NPM account
  • Node.js installed
  • NPM installed in your local machine (preferably latest version)

Create an NPM account

First things first you need to create an account with npm. Head over to npm and create an account. You will be prompted to choose a username of your choice.

With the help of your terminal, on the command line run the command;

npm login
This will prompt you to enter your username, followed by your password and your email address.
npm login

This will prompt you to enter your username, followed by your password and your email address.

After entering the correct details what remains is to now publish your package to npm.

After entering the correct details what remains is to now publish your package to npm.

Now navigate into your package.json file and check the name of the package.

If your package name is not yet taken you can proceed to the next step. In case your package name is already taken; you can choose another package name which suits you.

If your package name is not yet taken you can proceed to the next step. In case your package name is already taken; you can choose another package name which suits you.

Another important feature that you can use is to use your username together with your package name. For instance, you can use.

dev/vue3-boilerplate in case a name like vue3-boilerplate is taken and you would love to have such a name.

after confirming your preferred package name, now you need to publish your package to npm.

Also, to note that inside you package.json file if you have a property of private set to true you need to change it to false or you can delete the property entirely. Otherwise, NPM will throw us an error.

After doing so lets now publish our package to NPM.

To publish on the terminal command run the command down below.

The command will publish our package to npm you only need to wait for some little time and your package will be ready to be used.

The command will publish our package to npm you only need to wait for some little time and your package will be ready to be used.

Further reading

More Reading

Conclusion

Just to recap that we have seen how to publish a package to npm.

Thank you for reading through this article. If you found this piece helpful please do not hesitate to share it out.

Web developer, Life Café https://medium.com/life-cafe , Curious Soul, twitter at @amjohnphilip, Email: developerphilo@gmail.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store