How to create a NPM package 💭
What is npm?
Initially check does node is installed in your computer,
its returns the version of the installed package .
If its displays any error message install the latest version of the nodejs.
Check the version of the npm using
make sure your npm version is up-to date.Use the below command to install the latest npm.
npm install npm@latest -g
Before creating a package,We need to set some common properties that are gonna replicated in all packages.
npm set init-author-name “authorname”
npm set init-author-email “email id”
npm set init-author-url “author page”
if author’s page is not available skip it.
npm set init-license “license type”
Save the property using save-exact property
npm set save-exact true
add new user using
enter the username and email id.
if you don’t have the npm account just create a new one in NPM.
Create a New Folder for the package
Run “npm init” to initialize properties for your package.It will create package.json inside your folder.
Type package name,version,entry point(index.js),description,test command,git repo,keywords,license details.
open the package.json file
Create entry point(index.js)
After adding all the dependencies,publish the package using
Additional to that add the README.md file before publishing the package.The content in the read me file will be displayed in the NPM package page for the users to understand the package.
If there are any updates after the package is published.You can version your package, If its
eg. 1.0.0 → 1.0.1
npm version patch
eg. 1.0.0 → 1.1.0
npm version minor
eg. 1.0.0 → 2.0.0
npm version major
Then publish the package using,
That’s it !! Now you are owning a package in NPM :)
Happy publishing :)