Search code examples
npmnexusartifactory

How should I set up a private npm registry?


For a company project, I'd like to set up a private npm registry using Artifactory or Nexus, so packages can be shared with everyone without publishing them on https://registry.npmjs.org/

In maven I would set up a release and a snapshot repo. For resolving I would put them in a group alongside a proxy of maven central.

How does a setup for npm look like? npm's semver is able to differentiate release and prerelease, but I assume that routing them to different registries could be quite a difficult task.

On the other hand one might want to be able to have control over what gets pushed to the "release registry", implementing permissions accordingly. For this you would have to use a "prerelease" and a "release" registy.


Solution

  • In terms of how to do this in Nexus Repository if you really need to, I'd suggest setting up:

    npm-release (npm hosted) npm-prerelease (npm hosted) npm-all (npm group)

    Make the group include both members (so you can install using one URL), and then in your build script or whatever you are using to publish into Nexus Repository, just use the --registry flag to specify which repository you want to publish in to, something akin to this for a "release":

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

    And this for a "prerelease":

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

    Here are the npm docs for Nexus Repository 3.x if you need some more help: https://books.sonatype.com/nexus-book/reference3/npm.html