30

I need to run the latest version of Node and NPM on Windows. I installed Node 0.5.8 and downloaded the sources of NPM from GitHub. The steps I followed to install NPM were listed on its GitHub site but I have a problem running the following command:

node cli.js install npm -gf

but it fails with the following error message:

Error: connect UNKNOWN
at errnoException (net_uv.js:566:11)
at Object.afterConnect [as oncomplete] (net_uv.js:557:18)

System Windows_NT 5.1.2600
command "...\\Node\\bin\\node.exe" "...\\npm\\cli.js" "install" "npm" "-gf"
cwd ...\npm
node -v v0.5.8
npm -v 1.0.94
code UNKNOWN

I think that this is a problem because I need authentication at my proxy to connect to the Internet. But I found no way to tell the installer to use my credentials for login. Is there a possibility to provide my proxy IP and login information to npm installation maybe via command-line arguments?

I can provide the full log (but seems to have no more relevant information) using pastebin if needed.

migrated from stackoverflow.com Oct 17 '11 at 16:06

This question came from our site for professional and enthusiast programmers.

  • 6
    A little trick, if the user name contains the domain\user notation substitute the backslash with the http escape code (%5C) – user206475 Mar 12 '13 at 15:51
  • @layos Thank you sooooo much. If this was reddit, I'd give you gold. – Korinna May 17 '13 at 5:34

14 Answers 14

39

set http_proxy worked really well for me but I had to enter it in every time I opened the command prompt. So I had to combine multiple answers and now mine is permanent.

My sequence went as follows:

  • Go to C:\Users\YourUserName
  • Create a file named .npmrc
  • Inside that file type the following (if you are on an AD domain):

proxy = http://domain\\username:password@ip:port

  • Or use this is you are NOT on an AD domain:

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

  • Save the File
  • Open a command prompt and try to use npm

Others have had extra success with the following extra command:

strict-ssl = false

*You should be able to use an IP address or the URL to the proxy in place of "IP" above.

Your proxy string may need to be tweaked a bit, but this made it so that I didn't have to add this every single time.

Cheers

  • 3
    Heads up, if your password contains "@" npm won't parse your proxy setting correctly. A potential workaround is to put a bogus username:password in the npm config, and use a local proxy (like fiddler) to modify the request's Proxy-Authorization header to have the correct username:password. Keep in mind the the username:password stored in Proxy-Authorization is base64 encoded. – BStruthers May 21 '13 at 13:26
  • 9
    Got mine to work with: proxy = http://ip:port/ https-proxy = http://ip:port/ registry = http://registry.npmjs.org/ strict-ssl = false – Luke Dec 18 '13 at 19:51
  • 1
    didnt get mine to work with username:password – philx_x Aug 28 '15 at 14:37
  • 1
    Hey, I tried using domain\\user:password@urltoproxy:port however, when I run npm install the option changes to domain/user:password@urltoproxy:port So how do I work around this? – Jacob Schneider Nov 25 '18 at 23:49
  • I'm having the same issue as @JacobSchneider, on my .npmrc: -ssl=false registry=http://registry.npmjs.org/ proxy=http://domain\\username:password#@proxy.url:8080 then when I get setting from config with npm config get proxy: http://domain/username:password#@proxy.url:8080 note that the escaped backslash '\\' changes to a forward slash '/' – pompalini Apr 4 at 11:18
10

Maybe setting an environment variable will work for you:

set HTTP_PROXY=http://user:pass@server.url:port

(In my case, this solves the "connect UNKNOWN", but I get a completely different "socket hang up" error. I also tried setting the HTTPS_PROXY environment variable, but got the same result.)

  • I tried setting the environment variable and also tried passing --proxy user:pass@server.url:port to the command but now I alway get ECONNREFUSED.. Do I need to specify my AD domain for the proxy login? – Tobias Oct 20 '11 at 7:14
  • @Tobias try set HTTP_PROXY=http://domain\user:pass@server.url:port – Adam Grant Jul 3 '13 at 20:40
8

I had this identical issue and here's what I did to make this work:

  • Go to: C:\Users\YourUserName
  • Create a file named .npmrc
  • And it's entry will read:

    registry = http://registry.npmjs.org
    
  • Try the command node cli.js install npm -gf again.

  • I created the file with the contents you mentioned but still getting the connect UNKNOWN error :( – Tobias Nov 18 '11 at 7:09
  • Cheers for this. Did a "npm config set registry registry.npmjs.org" to get around the https:// and all is well on my windows setup. – Gavin Gilmour Mar 26 '12 at 7:34
  • 1
    if somebody gets the ETIMEOUT message add proxy setting with node config set proxy http://username:password@server:port – Jeremy S. May 8 '12 at 9:53
  • What worked for me was creating the ~/.npmrc file like above, which tells npm to use the http:// registry instead of https://, and then setting my http_proxy environment variable to http://myusername:mypassword@proxy.company.com:1234 – Maxy-B Sep 7 '12 at 17:38
  • Heads up, if your password contains "@" npm won't parse your proxy setting correctly. A potential workaround is to put a bogus username:password in the npm config, and use a local proxy (like fiddler) to modify the request's Proxy-Authorization header to have the correct username:password. Keep in mind the the username:password stored in Proxy-Authorization is base64 encoded. – BStruthers May 21 '13 at 13:26
4

After some research, I could use it in this way:

  1. Install NTLM Authorization Proxy Server or another proxy server for NTLM, like Cntlm. Personally, I prefer the python server, because I can tinker with it, and performance is not a problem.

  2. Set up the configuration; note that in my case, I had to enable both LM and NT mode, and I would suspect it being the normal case, nowadays.

  3. Set http_proxy and https_proxy environment variable to point to your local proxy:

    set http_proxy="localhost:5865"
    set https_proxy="localhost:5865"

  4. npm should work now, of course it should be executed from a shell where the above environment variables are defined.

3

The following worked for me.

On Windows 7:

npm config set proxy xxhttp://username:password@proxyhost:port# 

This should create a file named .npmrc in the C:/users/<username> folder.

3

Type this in command line:

npm set proxy http://user:pass@ip:port

npm set https-proxy http://user:pass@ip:port

DONT FORGET TO INCLUDE HTTP:// before your username. It worked for me.

2

This issue resolved for me after creating the .npmrc file as above, and then running the adduser command and following cmd prompts.

npm adduser

Run the following comman to see if you have an authorised username:

npm whoami
2

Each one of the above answers needs the user to write her password in a text file, or in an environ ment variable.

Personally I didn't like a solution like these, for their insecure approach. So I tried to write an application which injects the Kerberos token of the current user in the exchanges between the client (npm, bower, git) and the proxy. That said, Active Directory is just a proprietary implementation of Kerberos.

I use this software everyday, on a Windows 8.1 host. You can find the code (golang) and the first release binaries on https://github.com/nilleb/authentication-proxy.

1

All three things worked for me in .npmrc

proxy = http://unam:pwd@host:port
https-proxy = http://unam:pwd@host:port
registry = http://registry.npmjs.org
1

At least in Windows, it works for me with the following setting:

proxy=http://domain%5Cusername:password@proxy_ip:port

i.e., (1) use %5C instead of \ (as suggested elsewhere) and (2) use the IP address instead of the local machine name for the proxy server.

  • This is correct - the domain+username and the password need to be URL encoded separately. E.g. if you have # in your password, replace it with %23 – saille Aug 14 '15 at 1:00
1

You will get the proxy host and port from your server administrator or support.

After that set up

npm config set http_proxy http://username:password@proxyofmycomp.com:itsport
npm config set proxy http://username:password@proxyofmycomp.com:itsport

If there any special character in password try with % urlencode. Eg:- pound(hash) shuold be replaced by %23.

  • 2
    Which versions does your answer apply to given that the question was asked over 3 years ago? – Jason Aller Jul 7 '15 at 23:15
  • I belive it does not matter. I found the solution to this problem after trying a lot and never knew that my password was making issue.In order to make it perfect anwser no matter question was asked even before ten years :)... – Shamseer Jul 8 '15 at 18:06
0

The solution worked for me is the following:

npm config set http_proxy http://username:password@host/IP:port

npm config set proxy http://username:password@host/IP:port

replace the parameters with the values, in my case

username: (empty)

password: (empty)

host/IP : 192.36.36.110

port : 8080

so My commands are

npm config set http_proxy http://:@192.36.36.110:8080

npm config set proxy http://:@192.36.36.110:8080

0

CNTLM didn't work for me. I tried all possible combinations. NPM was giving Authentication error. Fiddler came for rescue and saved my time. It is easy to install and configure. Set Fiddler Rule to Automatically Authenticated.In .npmrc set these

registry=http://registry.npmjs.org
proxy=http://127.0.0.1:8888
https-proxy=http://127.0.0.1:8888
http-proxy=http://127.0.0.1:8888
strict-ssl=false

It worked for me :)

0

What worked for me was as follows:

registry=http://registry.npmjs.org
proxy=http://<url.pac>
https-proxy=http://<url.pac>
http-proxy=http://<url.pac>
strict-ssl=false

I did not have to enter any usernames or passwords, simply the PAC file url.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.