25

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

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?

Thanks

Funky
  • 12,890
  • 35
  • 106
  • 161
  • use this [solution](https://stackoverflow.com/questions/48224025/npm-behind-a-proxy-with-the-character-in-my-password/50214574#50214574). it worked for me. – saeid mohammad hashem May 07 '18 at 12:56
  • 2
    Be sure to URL encode `@` in passwords as `%40`. Otherwise it will probably think `ninjadev:5trongP` is the user/pass and `ssw0rd"@proxy.some-bigcorp.com` (or something similar) will be the host. – Captain Man May 15 '19 at 17:40

5 Answers5

38

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?

robmass
  • 651
  • 8
  • 10
  • 1
    Note that password containing **@** cannot be parsed. – Faizan Mubasher Feb 19 '19 at 07:56
  • 3
    @FaizanMubasher for passwords with an `@` or other meaningful special characters, replace them by their `encodeURIComponent` versions. For example, `@` becomes `%40`. – Pedro A Mar 12 '19 at 16:33
15

This worked for me:

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

Whithout http/https before.

Supersharp
  • 29,002
  • 9
  • 92
  • 134
3

The following code worked for me:

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

Jose R
  • 738
  • 2
  • 10
  • 26
1

This thing worked for me:

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

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

Jose R
  • 738
  • 2
  • 10
  • 26
Sarath Chandra
  • 101
  • 1
  • 1
0

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

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

https-proxy=http://username:password@proxyhostname:port
Blue
  • 22,608
  • 7
  • 62
  • 92
Saurabh Raj
  • 107
  • 1
  • 4
  • 2
    From Review: Hi, this post does not seem to provide a [quality answer](https://stackoverflow.com/help/how-to-answer) to the question. Please either edit your answer and improve it, or just post it as a comment. – sɐunıɔןɐqɐp Jan 21 '19 at 11:36