6
2608

How to publish NPM Package to Nexus Repo

Reading Time: < 1 minute

Due to some security or privacy, you may have a need to host a private NPM repository and publish created NPM packages from local environment.

In this illustration, we will assume that there is a remote Nexus repository that is already setup with user login is enabled.

Step 1: Validate login

Ensure that we are able to login to our Nexus Repository without any issue.

Step 2: Add registry

Setup the registry to point to the remote Nexus repository we setup with command.

$ npm config set registry https://private_repo_url.com/repository/npm_int/

Step 3: Turn off SSL

Here, we will turn off strict SSL. This step is optional as it will depends on whether your remote Nexus URL has a valid SSL certificate.

$ npm config set strict-ssl false

Step 4: Add npm user

We will add our login information to npm config so that future login is not required.

$ npm adduser
Username: myusername
Password: mypassword
Email: (this IS public) [email protected]

Step 5: Update package.json

Since we want to publish the package to our Nexus, we need to update `package.json` file in our project with the below lines so that npm publish will automatically be using this URL.

"publishConfig" : {
  "registry": "https://private_repo_url.com/repository/npm_int/"
}

Step 6: Publish Package

Run the below command from root project directory will automatically publish to the URL configured in publishConfig. More information on publish command is also available if you required to publish with more options.

$ npm publish

Conclusion

It may be difficult to figure out the issue to publish NPM package to Nexus repository but by following the steps above, publish can be easily possible.

After publish, we will usually be pulling it to use in projects as import. We also have a tutorial here to discuss how to pull NPM packages in docker.

Show Comments

No Responses Yet

Leave a Reply