You can publish any directory that has apackage.json
file, e.g. anode module.
Creating a user
To publish, you must have a user on the npm registry. If you don't have one, create it withnpm adduser
. If you created one on the site, usenpm login
to store the credentials on the client.
Test: Usenpm config ls
to ensure that the credentials are stored on your client. Check that it has been added to the registry by going tohttps://npmjs.com/~.
Publishing the package
Usenpm publish
to publish the package.
Note that everything in the directory will be included unless it is ignored by a local.gitignore
or.npmignore
file as described innpm-developers
.
Also make sure there isn't already a package with the same name, owned by somebody else.
Test: Go tohttps://npmjs.com/package/<package>
. You should see the information for your new package.
Updating the package
When you make changes, you can update the package usingnpm version <update_type>
, where update_type is one of the semantic versioning release types, patch, minor, or major. This command will change the version number inpackage.json
. Note that this will also add a tag with this release number to your git repository if you have one.
After updating the version number, you cannpm publish
again.
Test: Go tohttps://npmjs.com/package/<package>
. The package number should be updated.
The README displayed on the site will not be updated unless a new version of your package is published, so you would need to runnpm version patch
andnpm publish
to have a documentation fix displayed on the site.