DEV Community

Bawantha Thilan
Bawantha Thilan

Posted on

How to Publish your awesome package to NPM

How to Publish your awesome package to NPM

For JavaScript developers, npmjs.com is a treasure!

You can find more than 1 Million packages there. ( Yeah, I agree all of them are not useful πŸ˜‰ )

We can install/download Packages like react, express, lodash etc into our projects very easily from the npmjs package repository with just one command.
Such as -

Many a time, we want to reuse our code to different artifacts. And it’s a very good practice in Software Engineering.

What we do a lot, we create an independent repo/project for the code we want to reuse and copy that project folder into a new application that does not scale well. 😞

To solve this issue, we can upload/publish our own code/package to npmjs.

And then we can download/install it to a new app and just import it where we need to use it.

This is also a great way to modularize your app.

For initializing npm, we can run this command in our project directly-

Now we can code our awesome Library and test it well before publishing to npmjs.

You should give a proper name and version in your package.json file

To publish, you need one npmjs account, you can create it here https://www.npmjs.com/signup .

Then you can login in your terminal-

You can put your credentials and you will be logged in!

Now, let’s do the final Publish…

Awesome!
Now if you have a look on your npmjs package page after loggin in on your browser, you can see your package is listed there.
Normally you should see it here https://www.npmjs.com/settings/{UserID}/packages

Publish your reusable code and have fun!

Cheers!

Top comments (0)