Is there a way to make npm install (the command) to work behind proxy?

Read about a proxy variable in a .npmrc file but it does not work. Trying to avoid manually downloading all require packages and installing.

Add Comment
28 Answer(s)

I solved this problem this way:

  1. I run this command:

    npm config set strict-ssl false 
  2. Then set npm to run with http, instead of https:

    npm config set registry "http://registry.npmjs.org/" 
  3. Then I install packages using this syntax:

    npm --proxy http://username:[email protected]:80 install packagename 

Skip the username:password part if proxy doesn’t require you to authenticate

EDIT: A friend of mine just pointed out that you may get NPM to work behind a proxy by setting BOTH HTTP_PROXY and HTTPS_PROXY environment variables, then issuing normally the command npm install express (for example)

EDIT2: As @BStruthers commented, keep in mind that passwords containing “@” wont be parsed correctly, if contains @ put the entire password in quotes

Answered on July 15, 2020.
Add Comment

Setup npm proxy

For HTTP:

npm config set proxy http://proxy_host:port 

For HTTPS:

use the https proxy address if there is one

npm config set https-proxy https://proxy.company.com:8080 

else reuse the http proxy address

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

Note: The https-proxy doesn’t have https as the protocol, but http.

Answered on July 15, 2020.
Add Comment

When in doubt, try all these commands, as I do:

npm config set registry http://registry.npmjs.org/ npm config set proxy http://myusername:[email protected]:8080 npm config set https-proxy http://myusername:[email protected]:8080 npm config set strict-ssl false set HTTPS_PROXY=http://myusername:[email protected]:8080 set HTTP_PROXY=http://myusername:[email protected]:8080 export HTTPS_PROXY=http://myusername:[email protected]:8080 export HTTP_PROXY=http://myusername:[email protected]:8080 export http_proxy=http://myusername:[email protected]:8080  npm --proxy http://myusername:[email protected]:8080 \ --without-ssl --insecure -g install 

=======

UPDATE

Put your settings into ~/.bashrc or ~/.bash_profile so you don’t have to worry about your settings everytime you open a new terminal window!

If your company is like mine, I have to change my password pretty often. So I added the following into my ~/.bashrc or ~/.bash_profile so that whenever I open a terminal, I know my npm is up to date!

  1. Simply paste the following code at the bottom of your ~/.bashrc file:

    ###################### # User Variables (Edit These!) ###################### username="myusername" password="mypassword" proxy="mycompany:8080"  ###################### # Environement Variables # (npm does use these variables, and they are vital to lots of applications) ###################### export HTTPS_PROXY="http://$username:$password@$proxy" export HTTP_PROXY="http://$username:$password@$proxy" export http_proxy="http://$username:$password@$proxy" export https_proxy="http://$username:$password@$proxy" export all_proxy="http://$username:$password@$proxy" export ftp_proxy="http://$username:$password@$proxy" export dns_proxy="http://$username:$password@$proxy" export rsync_proxy="http://$username:$password@$proxy" export no_proxy="127.0.0.10/8, localhost, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16"  ###################### # npm Settings ###################### npm config set registry http://registry.npmjs.org/ npm config set proxy "http://$username:$password@$proxy" npm config set https-proxy "http://$username:$password@$proxy" npm config set strict-ssl false echo "registry=http://registry.npmjs.org/" > ~/.npmrc echo "proxy=http://$username:$password@$proxy" >> ~/.npmrc echo "strict-ssl=false" >> ~/.npmrc echo "http-proxy=http://$username:$password@$proxy" >> ~/.npmrc echo "http_proxy=http://$username:$password@$proxy" >> ~/.npmrc echo "https_proxy=http://$username:$password@$proxy" >> ~/.npmrc echo "https-proxy=http://$username:$password@$proxy" >> ~/.npmrc  ###################### # WGET SETTINGS # (Bonus Settings! Not required for npm to work, but needed for lots of other programs) ###################### echo "https_proxy = http://$username:$password@$proxy/" > ~/.wgetrc echo "http_proxy = http://$username:$password@$proxy/" >> ~/.wgetrc echo "ftp_proxy = http://$username:$password@$proxy/" >> ~/.wgetrc echo "use_proxy = on" >> ~/.wgetrc  ###################### # CURL SETTINGS # (Bonus Settings! Not required for npm to work, but needed for lots of other programs) ###################### echo "proxy=http://$username:$password@$proxy" > ~/.curlrc 
  2. Then edit the “username”, “password”, and “proxy” fields in the code you pasted.

  3. Open a new terminal

  4. Check your settings by running npm config list and cat ~/.npmrc

  5. Try to install your module using

    • npm install __, or
    • npm --without-ssl --insecure install __, or
    • override your proxy settings by using npm --without-ssl --insecure --proxy http://username:password@proxy:8080 install __.
    • If you want the module to be available globally, add option -g
Add Comment

Have you tried command-line options instead of the .npmrc file?

I think something like npm --proxy http://proxy-server:8080/ install {package-name} worked for me.

I’ve also seen the following: npm config set proxy http://proxy-server:8080/

Answered on July 15, 2020.
Add Comment

Though there are already many good advice, for my environment(Windows 7, using PowerShell) and the last version available of node.js ( v8.1.2 ) all the above did not worked, except when I followed brunowego settings.

So check your settings with :

npm config list 

Settings behind a proxy:

npm config set registry http://registry.npmjs.org/ npm config set http-proxy http://username:password@ip:port npm config set https-proxy http://username:password@ip:port npm config set proxy http://username:password@ip:port npm set strict-ssl false 

Hope this will save time to someone

Answered on July 15, 2020.
Add Comment

This works for me in Windows:

npm config set proxy http://domain%5Cuser:pass@host:port 

If you are not in any domain, use:

npm config set proxy http://user:pass@host:port 

If your password contains special characters such as ",@,: and so on, replace them by their URL encoded values. For example "->%22, @->%40, :->%3A. %5C is used for the character \.

Answered on July 15, 2020.
Add Comment

To setup the http proxy have the -g flag set:

sudo npm config set proxy http://proxy_host:port -g

For https proxy, again make sure the -g flag is set:

sudo npm config set https-proxy http://proxy_host:port -g

Add Comment
$ npm config set proxy http://login:pass@host:port $ npm config set https-proxy http://login:pass@host:port 
Add Comment

This worked for me-

npm config set proxy http://proxy.company.com:8080 npm config set https-proxy http://proxy.company.com:8080 npm set strict-ssl=false 
Add Comment

vim ~/.npmrc in your Linux machine and add following. Don’t forget to add registry part as this cause failure in many cases.

proxy=http://<proxy-url>:<port> https-proxy=https://<proxy-url>:<port> registry=http://registry.npmjs.org/ 
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.