Make your own NPM package and publish it.

Syed Rafi
Fnplus Club
Published in
3 min readMar 8, 2019

NPM (Node Package Manager) is the package manager for JavaScript language which runs with the node.js runtime environment. Npm is the gigantic community where Developers can contribute their packages, which can help many more developers to take advantage of these packages, to create numerous projects. since 2010 Npm has reached its population across the World. NPM is the platform where we can see numerous crazy and productive packages developing by developers from all across the globe.

It’s ample for the intro just dive in…

Node_Modules

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

 npm init

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…..

npm init

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…

index.js and package.json

Publishing

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.

Semantic versioning.

make sure of digits in the version while updating a package.

check out my packages → https://www.npmjs.com/~syed_rafi_naqvi

find me at → https://www.linkedin.com/in/syed-rafi-naqvi-28566bb1/

Thank you. Happy publishing…😃

--

--