NPM mirror

How to configure a mirror for NPM

Although NPM is used for NodeJS packages rather than operating system ones, I'm including it here as Nexus will happily proxy them as well, improving build times as any downloads are local and not over your internet connection.

Create blob store

Just like for APT we'll create a blobstore just for NPM. This will be called npm to follow the same guidelines.

  1. Log in to Nexus and go to the admin page via the icon in the top nav bar.
  2. Select blob store, then Create blob store
  3. Under Type select File
  4. Under Name enter npm
  5. Select Create blob store to create it.

Create npm mirror

  1. Log in to Nexus and go to the admin page via the icon in the top nav bar.
  2. Select Repositories then the Create Repository
  3. Select npm (proxy) as the repository type.
  4. Now fill in the required fields.

    1. For name enter npm-proxy
    2. For Remote storage enter the repository url https://registry.npmjs.org
    3. For Blob store select the one you created earlier, npm if you are following my naming conventions.
  5. Once it's all filled in select Save and the Repositories list should now show it.

Create npm group

This is optional. If you are going to just mirror the core npm repository then you can skip this and just use npm-proxy directly.

However, Nexus supports grouping multiple repositories together with a group, where if it cannot find an artefact in the first one it would check the next one. This is seamless to the client as all it knows about is there's a single repository.

One use-case for this is if you have a hosted repository where you store your own private artefacts. In this instance you'd create the proxy as above, then an npm-hosted repository. The group would then include both of them as if it's just one.

I'd advise you should create the group with just npm-proxy present as then your npm clients will use the group, and you can then seamlessly change the underlying proxies separately. For example, using an alternate upstream npm repository instead of the default one. You can do the switch in nexus without changing any client.

  1. Log in to Nexus and go to the admin page via the icon in the top nav bar.
  2. Select Repositories then the Create Repository
  3. Select npm (group) as the repository type.
  4. Now fill in the required fields:

    1. For name enter npm-group
    2. Under member repositories you will see two lists.

      On the left hand side select the npm repositories you want to be a member of this group and select >. It should then appear on the right hand side.

      You can change the priority of the entries by selecting the repository name and clicking the up or down arrows. The higher a repository is in the list then they are checked first.

  5. Once it's all filled in select Save and the Repositories list should now show it.

Using the mirror

Once you have configured your repositories, you can then now point npm to use it. This is described in the Using Repository mirrors section.


Last modified October 30, 2021: Add npm repositories (ecebbba)