Today, we’ll be going through how to publish an NPM package. It will be quick and easy! We will be presuming you know basic npm and have node and npm and git installed.
(1) Create a git repository in a new folder by running
(2) Create a git repository on Github using the name of the package you want to create. (Go to Github.com and click ‘Create a New Repository’ in your user account. Google around for Github help if you have trouble.)
git remote add origin and then add the https address or ssh address of your github repo. This syncs the git repo with your local repo for all changes.
npm init inside the same directory. This creates the
package.json file for your npm package.
(5) Answer all the publishing questions about the description of the package, name of the package, version of the package (use semantic versioning), license, and author.
git add . to stage the changes in the directory for commiting.
git commit -m "adding package.json" in your command line, still in the same root directory.
git push origin master to push the changes already made.
(9) Write your node module in your own index.js file.
git add . ,
git commit -m "changes",
git push origin master to update with your code.
(10) When you are done with your code, run
npm publish to publish your package.
(11) Lastly, add the tag with the same version that you started the repo with in your npm init. i.e. 1.0.0 is the default. Run
git tag 1.0.0 to tag that version.
To verify that your package was published:
npm info packagenamehere which will bring you to the package location in a browser.
npm repo packagenamehere to go to the repository of the package.
“NPM Playbook”by PluralSight.