Introduction
In this article I am going to share with you the simplest way to create your own NPM package and Publish it to npmjs.com. Before that, if you are new to Node keyword or Node.js , you can follow some introductory stuff from below links :
In this article I am going to share with you the simplest way to create your own NPM package and Publish it to npmjs.com. Before that, if you are new to Node keyword or Node.js , you can follow some introductory stuff from below links :
Steps to create and initialize project with VS CODE
Step 1
Create new project in Visual Studio code

Here I have created an empty project named helloworldtest , and open it using VS CODE IDE
Step 2 - Create package.json file
Because at first glance we dont have anything , so we should create package.json file by executing following command
Step 1
Create new project in Visual Studio code

Here I have created an empty project named helloworldtest , and open it using VS CODE IDE
Step 2 - Create package.json file
Because at first glance we dont have anything , so we should create package.json file by executing following command
- npm init
By executing above command , there are some questions you should answer it as follows,

After entering command npm init , you can see that they ask you about name of project, but keep in mind that name should be small latters and can not contain digits
Step-3
Then the next step to specify version

I have given 1.0.0 but you can give version as appropriate for your package release
Step-4
Than provide description about package and entry point of your package when project is loaded

As you can see in the above screenshot, I have provided a simple description that would publish when someone goes through your package
Step-5
Some more steps like Providing git repository , keywords and Author name to identify the creator of current package

I have entered some details like helloworldtest [which is unique by the way] and test command
NOTE
I have not provided git repository , but if you already have created empty repository you can specify its URL
Step-6
Last step is a summary , in which you can see all the information provided by you

That's it , we have created package.json file with all the needed information
NOTE
Before we publish package we should have account created with npmjs.com site , so that we can publish it by login credential .
Steps to create user and login through VS CODE
Step 1
Firstly we need to add user by using following command

After entering command npm init , you can see that they ask you about name of project, but keep in mind that name should be small latters and can not contain digits
Step-3
Then the next step to specify version
I have given 1.0.0 but you can give version as appropriate for your package release
Step-4
Than provide description about package and entry point of your package when project is loaded

As you can see in the above screenshot, I have provided a simple description that would publish when someone goes through your package
Step-5
Some more steps like Providing git repository , keywords and Author name to identify the creator of current package

I have entered some details like helloworldtest [which is unique by the way] and test command
NOTE
I have not provided git repository , but if you already have created empty repository you can specify its URL
Step-6
Last step is a summary , in which you can see all the information provided by you

That's it , we have created package.json file with all the needed information
NOTE
Before we publish package we should have account created with npmjs.com site , so that we can publish it by login credential .
Steps to create user and login through VS CODE
Step 1
Firstly we need to add user by using following command
- npm adduser
You can see following details after logging in,

By executing the above command they will ask you to enter username and password [which is hidden]
That's it , now user is created with your username.
Step 2
If you want to check whether user is created or not , write following command

By executing the above command they will ask you to enter username and password [which is hidden]
That's it , now user is created with your username.
Step 2
If you want to check whether user is created or not , write following command
- npm whoami
It shows me that user is created and logged in already
Steps To Publish NPM Package at npmjs.com
Step 1
Create simple js file in VS Code and named it Hello.js or whatever you want and write some code like below,
But before that you should install express as shown below,

Step 2
Write below code into Hello.js file,
- // Using NPM Package
- var express = require('express');
- var app = new express();
- // To define Port Number
- var portnumber = 3500;
- // To Print static text
- app.get('/', function(req, res) {
- res.send('<h1>Hello FOO !!!</h1>');
- });
Now your package is ready to publish by writing the following command
- npm publish
Step 4
Now you can see that your package is published to npmjs.com , just go to your account,

Now you can see that your package is published to npmjs.com , just go to your account,

That's it , your package is created. And if you want to use my package you can write
- npm install hellofootest
Conclusion
So we have learned what is NPM , its usage , and how to create npm package and publish at npmjs.com. If you found something that I have missed , feel free to suggest it to me.
Feedback is always accepted. Thanks
So we have learned what is NPM , its usage , and how to create npm package and publish at npmjs.com. If you found something that I have missed , feel free to suggest it to me.
Feedback is always accepted. Thanks

Sumit ChaudharyPosted Mar 1, 2018, 11:21 AM
Good one this and also explained.
Bikash SahuPosted Feb 26, 2018, 10:45 PM
Well explained and nice article.
Hemal JoshiPosted Jan 8, 2018, 7:51 AM
Good Going Brother
Manav PandyaPosted Dec 31, 2017, 2:59 AM
Glad you like it sir Dharmraj Thakur ..............
Dharmraj ThakurPosted Dec 31, 2017, 2:53 AM
Nice content and explaination...
Manav PandyaPosted Dec 30, 2017, 1:03 AM
Thanks Sir Hiten Pandya ...............
Hiten PandyaPosted Dec 30, 2017, 12:47 AM
Good one..Thanks for sharing....
Manav PandyaPosted Dec 30, 2017, 12:17 AM
Thanks for ur comment sir Bhavesh Jadav ........
Bhavesh JadavPosted Dec 29, 2017, 11:44 PM
Thank Manav, helpful article...
Manav PandyaPosted Dec 29, 2017, 11:10 PM
Thanks for ur comment sir Naresh Singhal ...........
Naresh SinghalPosted Dec 29, 2017, 11:09 PM
Very Nice Article Manav, Explained well in deep , Keep it on ....
Manav PandyaPosted Dec 29, 2017, 11:08 PM
Glad you like it Ahsan Siddique ...........
Ahsan SiddiquePosted Dec 29, 2017, 1:42 PM
Nice friend....keep it up