node.js 如何在使用 git remote url 进行 npm install 时指定注册表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35622933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to specify registry while doing npm install with git remote url?
提问by gurvinder372
I want to be able to clone a git repository using a URL as specified here
我希望能够使用此处指定的 URL 克隆 git 存储库
<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish>]
<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish>]
I am getting an error saying
我收到一条错误消息
npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/XYZ
npm 错误!404 注册表为https://registry.npmjs.org/XYZ 上的GET 返回 404
So I should also be able to specify the registry while doing since modules are supposed to be picked up from a internal repository.
所以我也应该能够在做的时候指定注册表,因为模块应该从内部存储库中获取。
Is it possible to specify registrywhile doing npm installwith git remote url?
是否可以在使用git remote url进行npm install时指定注册表?
回答by Alexandr Lazarev
npmgets its config settings from the command line, environment variables, and npmrc files. You can try to specify registry in a npmrc file, and module in the command line.
To change registry, you can use command:
npm从命令行、环境变量和 npmrc 文件获取其配置设置。您可以尝试在 npmrc 文件中指定注册表,并在命令行中指定模块。要更改注册表,您可以使用命令:
npm config set registry <registry url>
You can also change configs with the help of --argument. Putting --foo baron the command line sets the foo configuration parameter to "bar". So you can try something like that:
您还可以在--参数的帮助下更改配置。放在--foo bar命令行上将 foo 配置参数设置为“ bar”。所以你可以尝试这样的事情:
npm install http://git.repo.url --registry https://your.registry.local/
回答by bawa g
Not the best way but If you are using mac or linux even in you can set alias for different registries.
不是最好的方法,但如果您使用的是 mac 或 linux,您甚至可以为不同的注册表设置别名。
##############NPM ALIASES######################
alias npm-default='npm config set registry https://registry.npmjs.org'
alias npm-sinopia='npm config set registry http://localhost:4873/'

