Skip to main content

Publish Package to NPM

NPM (Node Package Manager) is a package manger for Javascript modules/libraries. Today, there are more than 1,6 millions available packages in NPM.

Before you can publish your packages or modules to NPM registry, you must create an account in https://www.npmjs.com/

The steps for publishing is as follows:

1. Open terminal then login to your NPM account.

npm login

2. Navigate into your package project directory.

cd /path/to/your/project

3. Initiate NPM package. For preventing name conflict with other existing packages, you may specify a scope in initiating a project.

npm init --scope=@your-username
This action will set name property in package.json into "@your-username/your-project-name".

4.  If you use versioning tools like Git in your project, you should set the current version of the project and align it with version property in package.json file.

git tag -a v0.1.0 -m "First version for testing app."
git push origin v0.1.0

5. Publish your project to NPM. Because of free NPM account and scoped project, you need to set --access parameter to public manually. Private package access is only for paid members of npmjs.com.

npm publish --access public

6. For deleting published package, you can run this command.

npm unpublish <package-name>@<package-version>
NPM

Comments