Create and Publish Your First NPM Package


As a developer, especially the one who usually uses or downloads packages from NPMJS.COM, have you ever wondered on how NPM packages were created? On this post, I'll guide and show you how to create one that might be useful, not only on your needs, but also to the other developers out there.

Jan. 24, 2022

I created my first package in the year 2020. I felt like it's already too late to create my own because a lot of NPM packages are already out there, but it didn't stop me to at least try to create one. For all the packages I initially created so far, one of them seems to at least reaches a lot of developers and invited some friendly contributors to enhance the existing codes. It is such a privilege that I become part of that package and helping those developers who are using our open source package.

This package is: check-password-strength

Enough intro, so let's get started on how to create and publish your first NPM package.

Steps on Creating and Publishing NPM Package.
#1. Register an account (If you don't have one yet)

https://www.npmjs.com/signup

#2. Setup your package locally.

2.1 Run this command on terminal or cmd. npm init and provide package description.

In this example, we are going to use jest to run a test in our basic package. so let's install jest npm i jest --save-dev

I prepared this sample code already but you can have a reference to this.

#3. Publish the package.

3.1 Run the npm publish --access=public

In my case, there's an OTP I setup up under Two Factor Authentication in my Account Settings (https://www.npmjs.com/settings/your_username/profile).

Once it's done, you may go to this to view all your packages: https://www.npmjs.com/settings/your_username/packages

If you have some questions or comments, please drop it below 👇 :)

Buy Me A Tea