-
Notifications
You must be signed in to change notification settings - Fork 196
Package Creation ‐ Instruction
Abhay Gupta edited this page Aug 29, 2024
·
1 revision
A guide for creating and publishing the NPM Package. This guide is designed as a task of GSOC'24 by Abhay Gupta.
Offical Documentation - https://docs.npmjs.com/cli/v10/using-npm/developers
- We need a
package.json
file inside our subfolder- From the terminal go inside the folder then run
npm init
, and follow up the instructions. This will create apackage.json
file.
- From the terminal go inside the folder then run
- Now, If we don’t want to pack the test folder in the package then we can mention the folder name in a file named
.npmignore
(which works similarly to.gitignore
). - Now, we have to add the user account on which we have to publish our package.
- Log in using →
npm login
, this will ask for the credentials.
- Log in using →
- After login, we are ready to run the final command →
npm publish
This will publish the package on the npm website!
- We can also test it locally before publishing to check whether all the things are working fine or not.
- After creating the
package.json
file, run the commandnpm link
. This will link the package locally on the machine. - Now, we can create a new node project and install our locally published package in that project by running
npm link <package-name>
. This will add the package or install it in the node modules folder. - After that, we can normally import the class and use it.
- After creating the