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 -
npm i react
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-
npm init
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
{
"name": "my-awesome-package",
"version": "1.0.0",
}
To publish, you need one npmjs account, you can create it here https://www.npmjs.com/signup .
Then you can login in your terminal-
npm login
You can put your credentials and you will be logged in!
Now, let's do the final Publish...
npm 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!
👋
As I am trying to contribute contents on the Web, you can buy me a coffee for my hours spent on all of these ❤️😊🌸
Top comments (4)
While we are at it, I might as well point you to my recent work on NPM publishing.
klap is a a zero config, zero dependency bundler for tiny javascript packages.
dev.to/osdevisnot/show-dev-introdu...
Thanks for sharing 👍
Will have a look!
I have published my package .Thanks Sir
Awesome! You are welcome!