node.js set unset - Is there a way to make npm install (the command) to work behind proxy?

13 Answers

Setup npm proxy


npm config set proxy http://proxy_host:port


npm config set https-proxy

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

config username password

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

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/

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

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

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


Try to find .npmrc in C:\Users\.npmrc

then open (notepad), write, and save inside :


PS : remove "<" and ">" please !!

Use below command at cmd or GIT Bash or other prompt

$ npm config set proxy ""

$ npm config set https-proxy ""

where is proxy ip and 4128 is port. change according to your proxy settings. its works for me.

After tying different answers finally, @Kayvar answers's first four lines help me to solve the issue:

npm config set registry
npm config set proxy
npm config set https-proxy
npm config set strict-ssl false

A lot of applications (e.g. npm) can use proxy setting from user environment variables.

You can just add to your environment following variables HTTP_PROXY and HTTPS_PROXY that will have the same value for each one


For example if you have Windows you can add proxy as follow:

There has been many answers above for this question, but none of those worked for me. All of them mentioned to add http:// prefix. So I added it too. All failed.

It finally works after I accidentally removed http:// prefix. Final config is like this:

npm config set registry
npm config set http-proxy ip:port
npm config set https-proxy ip:port
npm config set proxy ip:port
npm set strict-ssl false

I don't know the logic behind this, but it worked. If none of answers above works for you, maybe you can have a try on this way. Hope this one is useful.

My issue came down to a silly mistake on my part. As I had quickly one day dropped my proxies into a windows *.bat file (http_proxy, https_proxy, and ftp_proxy), I forgot to escape the special characters for the url-encoded domain\user (%5C) and password having the question mark '?' (%3F). That is to say, once you have the encoded command, don't forget to escape the '%' in the bat file command.

I changed

set http_proxy=http://domain%5Cuser:password%3F@myproxy:8080


set http_proxy=http://domain%%5Cuser:password%%3F@myproxy:8080

Maybe it's an edge case but hopefully it helps someone.

Finally i have managed to solve this problem being behinde proxy with AD authentication. I had to execute:

npm config set proxy http://domain%5Cuser:password@proxy:port/
npm config set https-proxy http://domain%5Cuser:password@proxy:port/

It is very important to URL encode any special chars like backshlash or # In my case i had to encode

  1. backshlash with %5C so domain\user will be domain%5Cuser
  2. # sign with %23%0A so password like Password#2 will be Password%23%0A2

I have also added following settings:

npm config set strict-ssl false
npm config set registry



node.js   npm