简体   繁体   English

如何在公司Web代理后面设置Node.js和Npm

[英]How to setup Node.js and Npm behind a corporate web proxy

How can I configure node.js and npm to run behind a web proxy? 如何配置node.jsnpm在Web代理后面运行?

I tried the following solutions but they didn't work for me. 我尝试了以下解决方案,但它们对我不起作用。

npm config set proxy http://proxy.company.com:8080

and

npm config set proxy http://username:password@proxy.company.com:8080

First open a command console at the location of your npm installation. 首先在npm安装位置打开命令控制台。

Then you can configure your npm to use a proxy using the commands: 然后,您可以使用以下命令将npm配置为使用代理:

npm config set proxy http://{url}:{port}
npm config set https-proxy http://{url}:{port}

Notice the protocol is set to http for both the proxy and https-proxy variables. 注意协议设置为http两者的proxyhttps-proxy变量。

If you would like npm to store your credentials for the proxy, you can additionally modify the commands as follows: 如果您希望npm存储代理的凭据,则可以如下另外修改命令:

npm config set proxy http://{username}:{passphrase}@{url}:{port}
npm config set https-proxy http://{username}:{passphrase}@{url}:{port}

For example: 例如:

npm config set proxy http://LanguidSquid:Password1@my.company.com:8080
npm config set https-proxy http://LanguidSquid:Password1@my.company.com:8080

Additional information here: Using npm behind corporate proxy .pac 此处的其他信息: 在公司代理.pac之后使用npm

This worked for me! 这对我有用!

  1. npm config set strict-ssl false npm config set strict-ssl false
  2. npm config set registry https://registry.npmjs.org/ npm配置设置注册表https://registry.npmjs.org/
  3. npm config set proxy http://login:pass@host:port npm配置设置代理http:// login:pass @ host:port
  4. npm config set https-proxy http://login:pass@host:port npm config设置https-proxy http:// login:pass @ host:port

NOTE: Remember to add https:// instead of http:// when setting registry 注意:请记住在设置注册表时添加https://而不是http://

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM