node.js 节点 NPM 代理身份验证 - 如何配置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40171953/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:47:05  来源:igfitidea点击:

Node NPM proxy authentication - how do I configure it?

node.jsproxynpmhttp-proxy

提问by Funky

I'm new to Node and trying to install TypeScript using the following command:

我是 Node 的新手,并尝试使用以下命令安装 TypeScript:

npm install -g typescript

I get the following error:

我收到以下错误:

if you are behind a proxy, please make sure that the 'proxy' config is set properly.

I have set my proxy using the following commands:

我已经使用以下命令设置了我的代理:

npm config set proxy http://Username:Pa55w0rd@proxyhostname
npm config set https-proxy http://Username:Pa55w0rd@proxyhostname

and tried this also:

也试过这个:

npm config set proxy http://"ninjadev:5trongP@ssw0rd"@proxy.some-bigcorp.com
npm config set https-proxy http://"ninjadev:5trongP@ssw0rd"@proxy.some-bigcorp.com

But none of them work. I am working behind a copmpany proxy with authentication, so I think this is stopping me from connecting. I have added my username and password and this also didn't work.

但它们都不起作用。我在一个带有身份验证的公司代理后面工作,所以我认为这阻止了我的连接。我已经添加了我的用户名和密码,但这也不起作用。

Does anyone have any idea how I can connect to npm whilst using the company proxy and authentication?

有没有人知道如何在使用公司代理和身份验证的同时连接到 npm?

Thanks

谢谢

回答by Roberto Massimini

Did you try with

你试过吗

npm config set proxy http://"ninjadev:5trongP@ssw0rd"@proxy.some-bigcorp.com:PORT
npm config set https-proxy http://"ninjadev:5trongP@ssw0rd"@proxy.some-bigcorp.com:PORT

where PORT can be 8080 if you don't have the proxy port?

如果您没有代理端口,那么 PORT 可以是 8080 吗?

回答by Supersharp

This worked for me:

这对我有用:

npm config set https-proxy "ninjadev:5trongP@ssw0rd"@proxy.some-bigcorp.com:PORT

Whithout http/httpsbefore.

内部消除http/https之前。

回答by Pietro Braga

The following code worked for me:

以下代码对我有用:

npm config set proxy "http://"username:password"@proxy.big-corp.com"

npm config set proxy "http://"username:password"@proxy.big-corp.com"

回答by Sarath Chandra

This thing worked for me:

这件事对我有用:

npm config set proxy http://"ninjadev:5trongP@ssw0rd"@proxy.some-bigcorp.com:PORT

npm config set proxy http://"ninjadev:5trongP@ssw0rd"@proxy.some-bigcorp.com:PORT

Open cmdas an administrator and past the command there. Modify the command with credentials provided for your user.

cmd以管理员身份打开并在那里传递命令。使用为您的用户提供的凭据修改命令。

回答by Saurabh Raj

In ubuntu-18.04 make sure that in home directory .npmrcfile contains:

在 ubuntu-18.04 中确保在主目录.npmrc文件中包含:

proxy=http://username:password@proxyhostname:port

https-proxy=http://username:password@proxyhostname:port