An Easy Guide to Publishing npm packages
Tags: npm, javascript, beginners, programming
Published: 2022-07-01 09:14:45

Anyone who has worked in JavaScript frameworks knows what a npm package is? And how important it is? So, what's your thought on publishing your own package? Ya, I know it is cool to install your own package using `npm i your_component_name` 🤩🤩. All these things are very meaningful to a beginner. It will definitely bring a smile on your face 😇.

Here, We are going to see some easy steps through which you can publish your npm package. For this first you have to build a component that you want to publish. After successfully creating a component just follow the below steps.

- Keep all required files of your component in a single folder let assume it is named as component. 
![component folder inside a folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uax8i6g1sswt8pob0xck.png)
(⚠️All required files of your component must be inside the component folder)

<br>
- Now create a index.js file inside this. Refer below image 👇

![creating index.js](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1lgbhfngj5q4e9izqkd.png)

- Now, just import and export your component in index.js file like this 👇

```
import your_component_name from './component/your_component_name'
export default your_component_name;
```
(Or, just open this folder with vs code, create a new file named index.js, write these two lines and save it.)
⚠️Replace your_component_name with your component name.



- If you don't have an npm account just goto npm on your browser and sign up. [click here to sign up with npm](https://www.npmjs.com/signup)

- Open cmd with in the same folder. Easy way just write cmd at place of your folders path and click enter. Refer below 👇

![opening cmd with in the same folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r83vvhfpg9p5j34e1ol3.png)

- Login to npm by this command `npm add user`
(It will ask your usename, password and email just give and log your self in)


- Now run this command `npm init`
It will ask package name, version, description, entry point, test command, git repository (if your component is in your git then give the repository link), keywords (these keywords are helpful for showing your package name in npm search), author (give like this your_name < your email id > ) and license ("MIT" or "ISC" which you like), then write yes and click enter.


- After the above you can see your package.json created over there.


- If you have used any third party library then just install them here by which all of these will listed as dependency in your package.json which will help user to get everything installed by a single npm install.


- Now, create a readme.md describing your component which will be shown in npm.


- Go back to cmd and run `npm publish`


- Now, you can see your package listed in npm.



🎉🎉🎉🎉🎉
Congratulations, you have successfully published your npm package.

[Link to my npm packages](https://www.npmjs.com/~saurabh19)

Thank you

Ways to reach me: 
- LinkedIn: [saurabh satapathy](https://www.linkedin.com/in/saurabh-satapathy-692a6a1b9/)
- Twitter: [SaurabhSatapat1](https://twitter.com/SaurabhSatapat1)
- GitHub: [saurabh190802](https://github.com/saurabh190802)
- Email: saurabhsatapathy0@gmail.com