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. (⚠️All required files of your component must be inside the component folder)
- Now create a index.js file inside this. Refer below image 👇
- 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
Open cmd with in the same folder. Easy way just write cmd at place of your folders path and click enter. Refer below 👇
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
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
Now, you can see your package listed in npm.
Congratulations, you have successfully published your npm package.
Ways to reach me: