Get Node.js npm command to work behind corporate proxy - node.js

I am trying to install bower
npm install -g bower
but am getting an authentication error from our proxy
...
npm http 407 http://registry.npmjs.org/bower
...
Error Code: 407 Proxy Authentication Required.
...
I am trying to get npm working behind a corprate proxy. I think our proxy is a little weird because the only way I was able to get maven downloading packages was to add wagon-http-lightweight.jar as a maven extension.
http://maven.apache.org/wagon/wagon-providers/wagon-http-lightweight/
I have tried all the regular things as described here:
Is there a way to make npm install (the command) to work behind proxy?
(I don't need to supply authentication details in my maven proxy settings).
npm config set registry http://registry.npmjs.org/
npm config set proxy http://myusername:mypassword#proxy.us.somecompany:8080
npm config set https-proxy http://myusername:mypassword#proxy.us.somecompany:8080
npm config set strict-ssl false
What else can I try?

Can try this....working for me.
Open IE (Chrome did not work for me).
Hit the URL http://registry.npmjs.org
it will download json output if successful.
Now go back to command prompt and try npm install.

I was able to get this working by installing a local proxy:
NPM behind NTLM proxy

Use fiddler http://www.telerik.com/fiddler
Install and run and that's it, everything will run as it is supposed to. I spent half a day cracking my head on this
Edit: I honestly have no idea if it was fiddler or something else I tried that fixed it (it is mostly the latter) but you should try setting registry, http-proxy, proxy and strict-ssl
When authentication is required for the HTTP proxy:
Fiddler can be configured to authenticate with the corporate HTTP proxy using NTLM or other protocols. Leave the existing auto authenticate options/rules defaults in place. Instead, go to this setting from the menu bar:
Tools > Telerik Fiddler Options > Connections tab
Click on the Allow remote computers to connect checkbox. You will see a dialog explaining the consequences of enabling this option. Restart Fiddler and update the .npmrc file as shown above. Whenever you need npm to access the registry site just run Fiddler. This setting won't affect the way Fiddler runs for other captures.

I have the same issue.
The root cause is my password contains a special character '#', when I npm set config proxy, the character become '#' in .npmrc file, so I change my password to remove the special character and it's working fine.
If your password does not contains special characters, just use syntax command below, it will work.
npm config set strict-ssl=false
npm config set proxy http://<username>:<password>#<proxy-server-url>:<port>
npm config set https-proxy http://<username>:<password>#<proxy-server-url>:<port>
Thanks,

Related

407 Authentication required npm

Hello everyone I´ve been trying to configure and use npm on my enterprise PC without success.
I´ve set proxy, https-proxy, strict-ssl false, registry http://registry.npmjs.org
proxy has been set like this "http://user:password#proxy_ip:proxy:port"
Where the password has a special character written in urlencode.
npm config get proxy
returns proxy with credentials as they should be.
I have cleared my npm cache and tried again.
No success.
Any ideas what can be the problem?
I recommend reading through this article to configure the proxy for npm.
http://wil.boayue.com/blog/2013/06/14/using-npm-behind-a-proxy/
npm config set proxy http://proxy.company.com:proxyport
npm config set http-proxy http://proxy.company.com:proxyport
npm config set https-proxy http://proxy.company.com:proxyport
Hope this is useful for you!
Usually, when you are behind a corporate proxy, it is needed to add the domain where you are at. Given that also the characters should be URL encoded, it would look like:
https://domain%5Cusername:password#proxy:port
We should add proxy with username and password to avoid this error.
For example:
username: admin
password: admin123
proxy: 172.10.3.21
port: 3128
npm config set proxy http://admin:admin123#172.10.3.21:3128
npm config set https-proxy http://admin:admin123#172.10.3.21:3128
Editing the .npmrc file in user folder worked for me.
I set the proxy and npm registry as follows:
proxy=http://username:password#proxy:port/
https-proxy=http://username:password#proxy:port
registry=http://registry.npmjs.org/
Note : for usenames and passwords containing special charcters, the characters need to be encoded in the proxy configuration.
e.g if username is "user" and password is "1234#user", then the .npmrc file will look like :
proxy=http://user:1234%40user#proxy:port/
https-proxy=http://user:1234#user#proxy:port
registry=http://registry.npmjs.org/
where, %40 is the encoded form of "#".
In my case, the pound symbol(#) was not getting accepted in username or password(Dont know why).
if you use windows and cntlm and you get a 407 error from cntlm proxy server, make sure that your PassNTLMv2 in the cntlm.ini is up-to-date, as you have to recreate it, everytime that you change domain password.
I had this error on my corporate machine and this command in Terminal fixed it:
proxyOn () {
export PROXY_CREDS=http://localhost:9000
export ALL_PROXY=${PROXY_CREDS}
export https_proxy=${PROXY_CREDS}
export http_proxy=${PROXY_CREDS}
export HTTP_PROXY=${PROXY_CREDS}
export HTTPS_PROXY=${PROXY_CREDS}
}
The character dot . , dont work on http request but &#46 remplace it
Before
npm config set proxy http://name.surname:pwrd#host:port
After
npm config set proxy http://name&#46surname:pwrd#host:port
As others mention above you should set both the proxy and https-proxy configuration variables. as below:
https-proxy=http://userName:password#urlOfYourProxy:8080/
What no mentions is that the https-proxy variable should point to a proxy url that uses the http protocol NOT the https protocol (as shown above)!! Pretty darned counter intuitive.

npm ETIMEDOUT code EMAXREDIRECT when running command npm i baconjs#0.7.88 -save

When I try to run the following command npm i baconjs#0.7.88 -save behind the proxy i get the ERR! code ETIMEDOUT error.
I have been getting this error when I am not logged on to the VPN. Now I have attempted all methods. Setting and Unsetting the proxies numerous times. Logging on and off the VPN with the proxies set/unset. no luck.
One thing I have noticed though is when I set the proxies and I have not logged on the vpn I get that error above (ERR! code ETIMEDOUT) but when I log on to the VPN and run the command I get a different error this time which is:
npm ERR! code EMAXREDIRECT
npm ERR! maximum redirect reached at: https:// registry.npmjs.org/registry.npmjs.org:
What do I need to do to get npm to successfully complete this command
npm i baconjs#0.7.88 -save. So frustrating this is, been at it for a couple of hours and I feel like putting this thing in the bin but I don't own it.
Different proxy methods I have tried
npm config set proxy http: //username:password#companyvpn.xx.xx:
npm config set https-proxy http: //username:password#companyvpn.xx.xx:
npm config set proxy http:// username:password#companyvpn.xx.xx
npm config set https-proxy http:// username:password#companyvpn.xx.xx
npm config set proxy http:// companyvpn.xx.xx
npm config set https-proxy http:// companyvpn.xx.xx
you would expect the first set of config to work but NO.Eventually I ran out of ideas
I tried with
npm config set https-proxy http://proxy:8080
It worked for me
Eventually I resorted to doing the install manually (downloading from github). It turns out that the problem had nothing to do with the npm config.
To fix this, the machine had some Enviroment Variables that are confingured for HTTP and HTTPS_PROXY. Before I was configuring these to match those of the npm config but no success.
What I did was delete these variables, they can be accessed via settings "Edit environment variables for your account". On windows > "Type here to search" located bottom left next to windows menu.
I deleted these variables and deleted the npm proxy config settings as well and then logged on to the company vpn, run npm and it was successful.
Behind the vpn proxy, I now only need to config npm with the company vpn and port number like so:
npm config set proxy http:// companyvpn.xx.xx:portNumber
npm config set https-proxy http:// companyvpn.xx.xx:portNumber
Some companies require adding username and password, some don't

Node NPM proxy authentication - how do I configure it?

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
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?
This worked for me:
npm config set https-proxy "ninjadev:5trongP#ssw0rd"#proxy.some-bigcorp.com:PORT
Whithout http/https before.
The following code worked for me:
npm config set proxy "http://"username:password"#proxy.big-corp.com"
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.
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

NPM behind NTLM proxy

Is it possible to run npm install behind an HTTP proxy, which uses NTLM authentication? If yes, how can I set the server's address and port, the username, and the password?
I solved it this way (OS: Windows XP SP3):
1. Download CNTLM installer and run it.
2. Find and fill in these fields in cntlm.ini. Do not fill in the Password field, it's never a good idea to store unencrypted passwords in text files.
Username YOUR_USERNAME
Domain YOUR_DOMAIN
Proxy YOUR_PROXY_IP:PORT
Listen 53128
3. Open console, and type these commands to generate password hashes.
> cd c:\the_install_directory_of_cntlm
> cntlm -H
Password: ...type proxy password here...
PassLM D6888AC8AE0EEE294D954420463215AE
PassNT 0E1FAED265D32EBBFB15F410D27994B2
PassNTLMv2 91E810C86B3FD1BD14342F945ED42CD6
4. Copy the above three lines into cntlm.ini, under the Domain field's line. Once more, do not fill in the Password field. Save cntlm.ini.
5. Open the Service Manager (from command line: services.msc), and start the service called "CNTLM Authentication Proxy".
6. In the console, type these lines:
> npm config set proxy http://localhost:53128
> npm config set https-proxy http://localhost:53128
> npm config set registry https://registry.npmjs.org
7. Now npm view, npm install etc. should work. Example:
> npm view qunit
...nice answer, no errors :)
CNTLM answer was working for me, but with connection errors make npm unusable. I've fixed them by adding this header in CNTML.
Header Connection: close
Another alternative is to use Px for Windows which talks NTLM on your behalf like Cntlm and NTLMAps without having to provide your credentials. It uses the logged in user's credentials via SSPI.
Rather than running CNTLM, you could instead try running Fiddler when you need to use npm. I've found this works in fairly locked down environments (e.g. investment banks). It's also a tool that is fairly easy to make a business case for (if you need to) since it's invaluable for checking/creating/altering HTTP traffic.
I've had to go this route before due to usage of smartpass authentication - i.e. we didn't actually have passwords. At those locations setting up CNTLM would have been impossible.
You can pass the settings as parameters:
npm --proxy=http://username:password#proxyserver:port --proxy-https=http://username:password#proxyserver:port --registry=http://registry.npmjs.org/ install whateveryouwanttoinstall
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 :)
Another Fiddler Option:
A second way to make Fiddler act as an HTTP proxy for NTLM and other protocols is to leave the auto authenticate options/rules defaults in place and go to this setting from the menu bar:
Tools > Telerik Fiddler Options > Connections tab
Click on the Allow remote computers to connect checkbox. You will see a dialog explaining the consequences of enabling this option. Restart Fiddler and update the .npmrc file as shown above. Whenever you need npm to access the registry site just run Fiddler. This setting won't affect the way Fiddler runs for other captures.
Open your .npmrc file in C:\users\username\ folder using notepad
Add the below lines..
Replace domain, username, pwd, servername with your correct values
Try to install or get packages now
If trying from Vs2017, close and reopen VS IDE, then only it works
proxy=http://DOMAIN%5CUSERNAME:PWD#proxy.servername.com:6050
https-proxy=http://DOMAIN%5CUSERNAME:PWD#proxy.servername.com:6050
http-proxy=http://DOMAIN%5CUSERNAME:PWD#proxy.servername.com:6050
strict-ssl=false
CNTLM worked for me as suggested by KOL. Thanks KOL for that. Just wanted to add that there are some oddities in individual proxies because of which the password may not be acceptable when using simple cntlm -H.
Use cntlm -I -M http://test.com and copy the below config after erasing older configs and you should be through.
The output is like
---------------------------------------------------
Auth NTLM
PassNT 8EE9B595A89F7D8774C2146FB302CBCF
PassLM 78901DA9889727EDE28EF9F2769485B9
----------------------------------------------------

NPM module installation error

I am getting Error: tunneling socket could not be established, cause=getaddrinfo ENOTFOUND while trying to install a module in node.js. It seems some proxy error.I checked in browser setting ,proxy is disabled. But when i am checking in command prompt npm config get proxy, getting 192.168.98.5:8080. How to disable this?
First, try to execute npm config delete proxy. If you get something like Error: ENOENT, unlink '/Users/drlazor/.npmrc' is OK; that means you don't have a npm config file and, therefore, no proxy settings.
Second, verify you have no proxy settings with npm config get proxy. You should get a nullor the above error. If you keep on getting a result different from null, you should also ensure you haven't set the environment variable HTTP_PROXY.
Third and last, if none of those worked, try accessing the URL from your browser; it could be a network issue after all.
You should check the npm config page on how to set and modify config values. proxy key stores proxy server to use to connect to npm repositories. Try this :
npm config delete proxy
Note: This Works if you are not behind a Proxy i.e (From a Personal Computer)
First execute this command
npm config edit
npm the configuration file opens
comment following two lines in the opened file by putting ";"(semi Colon) in start of the line.
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
You are done.
Now install any package you want to.
npm install -g cordova
npm install -g npm
or anything else you need to install
i was in the same state and got this error because of the wrong proxy value format
(i just miss "http://" at the beginning of the proxies values).
If a proxy should be set, here is the format (values depend of your network) :
npm config set proxy http://proxy.mydomain:3128
npm config set https-proxy http://proxy.mydomain:3128
This can also happen if your NPM is configured to use a different NPM registry server (possibly you are on a work machine and not connected to the network/VPN). To see if this is the case:
npm config edit
and look for:
registry=http://alternateurl
The default is:
https://registry.npmjs.org/
You can connect to your VPN/network or change that config to correct.
You need to set all 3 proxy
npm config set proxy http://proxy.name.xx:port
npm config set http-proxy http://proxy.name.xx:port
npm config set https-proxy http://proxy.name.xx:port
If you have no proxy use the following commands:
npm config delete https-proxy
npm config delete proxy
if you are using a proxy use:
npm config set proxy $PROXY
npm config set http-proxy $PROXY
Either of the two tend to work
In case setting proxy via terminal or creating .npmrc does not help, try to put .typingsrc file in c:\Users\'username' with the following content
{
"proxy": "http://proxy.name.xx:port",
"https-proxy": "http://proxy.name.xx:port",
"strict-ssl": false
}

Resources