 
 The Ultimate Guide to Publish an NPM Package (Step-by-Step)
Introduction
Hello folks, today I’m going to explain how to publish your Node package. NodeJS has got a very good stand for application developments. It became a new technology that everyone started to work with.
If you are a NodeJS developer, you might have noticed that during “npm install” it installs lots of packages. Well, that is the part of NodeJS, where third-party libraries are installed as a package.
Table of Contents
- Step 1: Initialize Your NPM Package
- Step 2: Create the Main File
- Step 3: Add a README File
- Step 4: Publish Your Module
- Step 5: Update and Republish
- Example Module
Step 1: Initialize Your NPM Package
The journey of writing an npm package starts with initializing npm in the dedicated directory of your package.
npm initProvide all the details as asked. In the end, it will generate the file package.json.

Step 2: Create the Main File
Create a file named index.js, which will contain all the logic of your Node module.
exports.msg = function () {
  console.log("hello all!");
}Step 3: Add a README File
You can provide details in the README.md file. This file is important to understand the purpose and important details of the module.
Step 4: Publish Your Module
To publish your module, execute the following command:
npm publish --access publicNote: Do remember that if you have not verified your email account on npmjs.com, it will not allow publishing your module.
Step 5: Update and Republish
After changing the logic of the module, publish it again with an updated version:
npm version patchThis will update the version of your Node module (for example, from 1.0.1 to 1.0.2). Then publish again using:
npm publishExample Module
I have created a new module called json-diff-change, which you can find below:
- GitHub Repository: https://github.com/savankoradia/json-diff-change
- NPM Package: https://www.npmjs.com/package/json-diff-change
