npm-installartifactorynpm-registry.npmrc

How to configure .npmrc file to be able to combine different NPM registries?


How to set an .npmrc file to tell npm install to download all the dependencies from https://registry.npmjs.org but only a specific one from a corporate Artifactory under https://artifactory.corporation.io/artifactory/npm/ that needs authentication using ?


Solution

  • We can configure https://registry.npmjs.org as a remote repository(test-npm-remote) in Artifactory. If you have any packages which were developed locally can be deployed to the local(test-npm-local) repository. We can create a virtual repository that consists of local and remote repositories and pull the npm artifacts using the virtual repository(test-npm). You can find more details in the below link. https://jfrog.com/screencast/setting-up-an-npm-registry-with-jfrog-artifactory-in-less-than-one-minute/

    npm config set registry http://art.local/artifactory/api/npm/test-npm/
    npm login
    <enter credentials>

    Sample NPM client configuration for your reference.

    $ cat ~/.npmrc                                                                    
    email=test@test.com
    always-auth=true
    registry=http://art.local/artifactory/api/npm/test-npm/
    //art.local/artifactory/api/npm/test-npm/:username=testuser
    //art.local/artifactory/api/npm/test-npm/:_password=XXXXXXX

    To install a package: npm install <PACKAGE_NAME>