It’s ample for the intro just dive in…
One of the heaviest objects of the universe is Node_Modules 🤣. To know heaviness of node_modules, just check any node_module folder present in your pc. To write your own npm package we should write whole node_modules from scratch. Just kidding…! npm will take care about the node modules we can concentrate only on building the npm package.
Just start crunching the code
To start any npm package we use
But we must get into some directory to npm init. after npm init, we will get a package.json in the project directory.
# To create a directory mkdir Desktop/hello_world# To change directory cd Desktop/hello_world
doing npm init we may get something like this…..
fill everything with proper information. This Info will display in the npm account and check twice for the package name in npmjs.com whether the same name already taken by someone else.
# create an index.js file
for the demo purpose, we are just consoled logging the “hello_world_npm_module“. Feel free to use any package in your package as a dependency.
# in index.js console.log("hello_world_npm_package")
save the file. upload it to GitHub, even without GitHub you can publish your package, if you want to share your code to everyone, you can fill git repository: with appropriate repository link to share the repo.
After filling package.json we can see something like this…
Finally, we will publish an npm package with its command.
# to publish npm publish
while publishing the npm package we want to give our credentials then npm will take care of everything. Before that, we must have npm account without npm account we can not publish the package. your npm package is published. check your npm account.
Updating (semantic versioning)
updating is a very important aspect of software development, The updating of npm package is known as semantic versioning. you can see “ version: (1.0.0)” while npm init, we should change the version while updating the npm package. each digit in the version has a unique name for unique change as major, minor and bug fixes (1.0.0). while updating change package version if not the package will not update. for the major change of package change first digit of version, for a minor change of package change the middle digit of version and for bug fixes change the last digit.
make sure of digits in the version while updating a package.
check out my packages → https://www.npmjs.com/~syed_rafi_naqvi
Thank you. Happy publishing…😃