In this post, you will learn how to use your Nexus npm proxy repository as a proxy for your node js project’s npm packages. You also learn how to concfigure npmrc for proxying npm packages from Nexus.
Advertisements
Nexus is a repository manager that helps in managing your project’s dependencies, artifacts & metadata, docker images, binaries, JARs and proxying to external repositories. It’s a must have tool when your project is incubated from early stages.
One of the users of Nexus is to proxy the npm packages to the official npm registry. Whenever you applications installs an npm package from the official npm registry, you can cache it to your Nexus repo manager and next time if your app tries to install the npm packages, it will be proxied from Nexus. This way you can speed up the installation time of your application. Here are the steps.
Create an npm proxy repository in Nexus
Create a new repository that proxies to the official npm registry.
Hash your Nexus login credentials
Hash your login credentials with the following command. I suggest you to use an account with developer role and not the admin role. We need this hash value later.
echo -n 'anand:nexus@123' | openssl base64 YW5hbmQ6bmV4dXNAMTIz
Add registry details to npmrc file
Create an npmrc file at the project level or globally and add the following details.
Registry URL, Email ID and Auth token that we created in the previous step.
registry=http://109.35.129.253:8083/repository/an-npm-proxy/ email=anand@poopcode.com always-auth=true _auth=YW5hbmQ6bmV4dXNAMTIz
Next time when you do an npm install, your npm packages will be cached to your Nexus.