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
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 fury.io supports that, 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 (npm is tied to only one registry). First you have to add a scope to all of your private packages.
Now with .npmrc
you can link the registries 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/
Noticed to the docs
Per-project config file
When working locally in a project, a .npmrc file in the root of the project (ie, a sibling of node_modules and package.json) will set config values specific to this project.
Note that this only applies to the root of the project that you're running npm in. It has no effect when your module is published. For example, you can't publish a module that forces itself to install globally, or in a different location.
I tried to create the files you specified in the question(package.json and .npmrc), everything working fine. Maybe you made a typo somewhere?
frgt$ npm i myPrivateLibFromNpmFury --verbose
npm info using [email protected]
npm info using [email protected]
npm verb request uri https://npm.fury.io/AUTH_TOKEN/me/myPrivateLibFromNpmFury
npm verb request no auth needed
npm info attempt registry request try #1 at 14:36:10
npm verb request id 23f09acc4e7021c7
npm http request GET https://npm.fury.io/AUTH_TOKEN/me/myPrivateLibFromNpmFury
npm http 403 https://npm.fury.io/AUTH_TOKEN/me/myPrivateLibFromNpmFury
You should use the seamless proxy:
registry=https://npm-proxy.fury.io/AUTH_TOKEN/me/