antpaw antpaw - 1 month ago 17
Javascript Question

using myproject/.npmrc with registry

How do I setup a .npmrc file inside my project where I can define my own private registry? I don't want to have this kind of configuration in my user config .npmrc. Every other developer should be able to just

git clone
the project and run
npm install
.

This is what I have so far:

// .npmrc
registry=https://npm.fury.io/AUTH_TOKEN/me/

// package.json:
{
"name": "webapp",
"description": "",
"version": "1.0.0",
"private": true,
"dependencies": {
"jquery": "1.2.3",
"myPrivateLibFromNpmFury": "0.0.4"
}
}


npm install myPrivateLibFromNpmFury


returns

npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/myPrivateLibFromNpmFury

Answer

As it was pointed out by @Paulpro and @Alexey B. the most parts of it worked already, but I couldn't see it right away, maybe because I didn't reload my bash environment properly. But after that I faced other issue with npm outdated that was caused by the registry url. It turns out npm can only have one registry url, (which is pretty crazy) and if you want to use private and public npm-modules you have to proxy the public npm-module registry through your private registry. Luckily this is what fury.io supports, so in my case instead of using this:

//.npmrc
registry=https://npm.fury.io/AUTH_TOKEN/me/

i have to use this:

//.npmrc
registry=https://npm-proxy.fury.io/AUTH_TOKEN/USER_NAME/

UPDATE: It is possible to work around the problem with npm tight to only one registry. First you have to add to all of your private packages a scope. With .npmrc you can now link the registery for the scopes, and you no longer need any proxies at all.

//.npmrc
@project_a:registry=https://npm.fury.io/AUTH_TOKEN/USER_NAME/
@project_b:registry=https://npm.fury.io/AUTH_TOKEN/USER_NAME/
@company_a:registry=https://npm.fury.io/AUTH_TOKEN/USER_NAME/