Skip to main content

Publishing npm Packages

Publishing your own packages to a npm hosted or group repository allows you to share packages across your organization or with external partners. With authentication configured you can publish your packages with the npm publish command. Review npm Security documentation for authentication requirements. Note that publishing to a group repository requires Sonatype Nexus Repository Pro.

Select Writable Repository to Publish to an npm Group

Using Nexus Repository Pro, you can push packages to a group repository. To use Nexus Repository Pro to push packages to a group, first select a Writable Repository in the configuration menu as shown below:

93487580.png

You can then continue with the instructions described below for publishing to the selected writable hosted repository.

Once a package is published to the private registry in Sonatype Nexus Repository, any other developers or build servers that access the repository manager via the repository group have instant access to it.

Set Registry Configuration Value

The npm publish command uses a registry configuration value to know where to publish your package. There are several ways to change the registry value to point at your hosted npm repository.

Since the .npmrc file usually contains a registry value intended only for getting new packages, a simple way to override this value is to provide a registry to the publish command:

npm publish --registry http://localhost:8081/repository/npm-internal/

Alternately, you can edit your package.json file and add a publishConfig section:

"publishConfig" : {
  "registry" : "http://localhost:8081/repository/npm-internal/"
}, 

Detailed information about package creation can be found on the npm website.

npm Scope Support

Sonatype Nexus Repository also supports using npm scope. Packages published to Nexus Repository with a defined scope are reflected with the scope value populating the repository group field in Browse and Search. Details on scoping are available on the npm website.