bower behind a proxy - node.js

bower install behind a proxy fails in timeout with the following settings (some set are useless...) :
git config --global http.proxy fr-proxy.example.com:3128
git config --global https.proxy fr-proxy.example.com:3128
export http_proxy=http://fr-proxy.example.com:3128
export https_proxy=http://fr-proxy.example.com:3128
npm config set proxy http://fr-proxy.example.com:3128
npm config set https-proxy http://fr-proxy.example.com:3128
npm config set registry http://registry.npmjs.org/
I have also tried an install/uninstall of bower and a bower clean cache.

Edit your .bowerrc file and add the wanted proxy configuration:
{
"proxy":"http://<host>:<port>",
"https-proxy":"http://<host>:<port>"
}
If working behind an authenticated proxy, user and password should be included like this:
{
"proxy":"http://<user>:<password>#<host>:<port>",
"https-proxy":"http://<user>:<password>#<host>:<port>"
}
Usually, the .bowerrc is next to the bower.json. And if there is no .bowerrc file near the bower.json file, you can create one by yourself.

I have problem with bower list command, which was caused by the fact that bower use git with git:// URLs to get the list of remote GitHub repositories, but git:// protocol is blocked by our corporate firewall. In order to solve this problem in addition to setting environment variables, I have to add extra configurations to git too. Here's full list of commands I have to execute (remember to replace proxy host and port with yours):
# set proxy for command line tools
export HTTP_PROXY=http://localhost:3128
export HTTPS_PROXY=http://localhost:3128
export http_proxy=http://localhost:3128
export https_proxy=http://localhost:3128
# add configuration to git command line tool
git config --global http.proxy http://localhost:3128
git config --global https.proxy http://localhost:3128
git config --global url."http://".insteadOf git://
Standard environment variables in Bash are uppercased, for proxy those are HTTP_PROXY and HTTPS_PROXY, but some tools expect them to be in lowercase, bower is one of those tools. This is why I prefer to have proxy set in 2 cases: lower and upper.
Bower is using git to get packages from GitHub, this is why configuration keys need to be added to git too. http.proxy and https.proxy are proxy settings and should point to your proxy. Last but not least you need to tell git not to use git:// protocol, because it may be blocked by firewall. You need to replace it with standard http:// protocol. Someones suggest to use https:// instead of git:// like following: git config --global url."https://".insteadOf git://, but I was getting Connection reset by peer error, so I'm using http://, which is working fine for me.
At home I don't use any proxy and don't have corporate firewall, so I prefer to switch back to "normal" no-proxy settings. Here's how I do it:
# remove proxy environment variables
unset HTTP_PROXY
unset HTTPS_PROXY
unset http_proxy
unset https_proxy
# remove git configurations
git config --global --unset http.proxy
git config --global --unset https.proxy
git config --global --unset url."http://".insteadOf
I'm not very good at remembering things, so I would never remember all those commands. On top of this I'm lazy and would not want to type those long commands by hand. This is why I was creating functions to set and unset proxy settings. Here's 2 functions I've added to my .bashrc file after some aliases definitions:
set_proxy() {
export HTTP_PROXY=http://localhost:3128
export HTTPS_PROXY=http://localhost:3128
# some tools uses lowercase env variables
export http_proxy=http://localhost:3128
export https_proxy=http://localhost:3128
# config git
git config --global http.proxy http://localhost:3128
git config --global https.proxy http://localhost:3128
git config --global url."http://".insteadOf git://
}
unset_proxy() {
unset HTTP_PROXY
unset HTTPS_PROXY
unset http_proxy
unset https_proxy
git config --global --unset http.proxy
git config --global --unset https.proxy
git config --global --unset url."http://".insteadOf
}
Now when I need to set proxy, I just execute set_proxy command, and to unset unset_proxy command. With the help of Bash's autocomplete I don't even need to type those commands, but let tab complete them for me.

My script (using git bash on Windows) for setting proxy was executed by a different user from the one I was using for bower. The environment variables were not taken into account.
So the following setting is sufficient, as specified in other answers:
export http_proxy=http://fr-proxy.example.com:3128
export https_proxy=http://fr-proxy.example.com:3128

If your OS is Linux or OS X try the following command
bash
http_proxy='proxy server' https_proxy='proxy server' bower

Related

How to specify registry while doing npm install with git remote url?

I want to be able to clone a git repository using a URL as specified here
<protocol>://[<user>[:<password>]#]<hostname>[:<port>][:][/]<path>[#<commit-ish>]
I am getting an error saying
npm ERR! 404 Registry returned 404 for GET on
https://registry.npmjs.org/XYZ
So I should also be able to specify the registry while doing since modules are supposed to be picked up from a internal repository.
Is it possible to specify registry while doing npm install with git remote url?
npm gets its config settings from the command line, environment variables, and npmrc files. You can try to specify registry in a npmrc file, and module in the command line.
To change registry, you can use command:
npm config set registry <registry url>
You can also change configs with the help of -- argument. Putting --foo bar on the command line sets the foo configuration parameter to "bar". So you can try something like that:
npm install http://git.repo.url --registry=https://your.registry.local/
Not the best way but If you are using mac or linux even in you can set alias for different registries.
##############NPM ALIASES######################
alias npm-default='npm config set registry https://registry.npmjs.org'
alias npm-sinopia='npm config set registry http://localhost:4873/'
Yes, you need to use:
npm config set registry <registry url>.
to make sure you install your package from the registry inside your company.
If you are doing npm -i -g, this is to install globally.
you need to do:
npm -g config set registry <registry url>

Problems on NodeJs, GitHub and IONIC connection by proxy

My contribution
I can't download dependencies on my job
I have error connection , by the proxy problems
This is my contribution
Install any package from NodeJs when you work on a company, and this company has a proxy, those line solve my life on my job. I hope be useful:
// when you have a package.json and you need install all
npm --proxy http://<your_account>:<your_password>#<ip_address>:<port_number> install
// Set as an environment proxy
npm config set proxy http://<your_account>:<your_password>#<ip_address>:<port_number>
npm config set https-proxy http://<your_account>:<your_password>#<ip_address>:<port_number>
// this is when you have some packages(dependencies) and those are stored on Github
git config --global http.proxy http://<your_account>:<your_password>#<ip_address>:<port_number>
git config --global https.proxy http://<your_account>:<your_password>#<ip_address>:<port_number>
// if you start with IONIC you will need set on the environment the proxy
set PROXY=http://<your_account>:<your_password>#<ip_address>:<port_number>
See you all

How to clear https proxy setting of NPM?

How can I clear the previous ssl proxy setting of NPM?
well, I search a lot, but all post I got is mainly about how to set proxy in corporate network.
I try to set proxy to nothing:
npm config set http-proxy
npm config set https-proxy
the first command pass yet the second one warn that:
npm WARN invalid config proxy=""
npm WARN invalid config Must be a full url with 'http://'
is the warning neglectable and I have successfully clear the proxy setting?
None of the above helped me, but this did:
npm config rm proxy
npm config rm https-proxy
Source: http://jonathanblog2000.blogspot.ch/2013/11/set-and-reset-proxy-for-git-and-npm.html
Try deleting them with:
npm config delete proxy
npm config delete https-proxy
npm config rm proxy
npm config rm https-proxy
unset HTTP_PROXY
unset HTTPS_PROXY
unset http_proxy
unset https_proxy
Damn finally this does the trick in Debian Jessie with privoxy (ad remover) installed, Thank you :-)
This was already answered but I think the --global config is not covered properly.
By running npm config rm proxy you remove proxy from user configuration. This can be easily verified by running: npm config list.
If there is proxy or https-proxy setting set in global config you have to use --global in the command to remove it.
So at the end this will clean-up proxies from both local and global configs:
npm config rm proxy
npm config rm https-proxy
npm config --global rm proxy
npm config --global rm https-proxy
In the latest version npm rm proxy does not work. Instead use npm rm http-proxy
npm config rm proxy
npm config rm https-proxy
By the default value npm is looking for packages from https://registry.npmjs.org. What you also need to do is override the registry and strict-ssl values.
npm config set registry "http://registry.npmjs.org"
npm config set strict-ssl false
If you go through the npm config documentation, it says:
proxy
Default: HTTP_PROXY or http_proxy environment variable, or
null
Type: url
As per this, to disable usage of proxy, proxy setting must be set to null. To set proxy value to null, one has to make sure that HTTP_PROXY or http_proxy environment variable is not set. So unset these environment variables and make sure that npm config ls -l shows proxy = null.
Also, it is important to note that:
Deleting http_proxy and https_proxy config settings alone will not
help if you still have HTTP_PROXY or http_proxy environment variable
is set to something and
Setting registry to use http:// and setting
strict-ssl to false will not help you if you are not behind a proxy
anyway and have HTTP_PROXY set to something.
It would have been better if npm had made the type of proxy setting to boolean to switch on/off the proxy usage. Or, they can introduce a new setting of sort use_proxy of type boolean.
I have used the below commands for removing any proxy set:
npm config rm proxy
npm config rm https-proxy
And it solved my problem :)
there is a simple way of deleting or removing the npm proxies.
npm config delete proxy
npm config delete https-proxy
I had the same problem once.
Follow these steps to delete proxy values:
1.To delete proxy in npm:
(-g is Important)
npm config delete proxy -g
npm config delete http-proxy -g
npm config delete https-proxy -g
Check the npm config file using:
npm config list
2.To delete system proxy:
set HTTP_PROXY=null
set HTTPS_PROXY=null
Now close the command line and open it to refresh the variables(proxy).
Nothing above worked for me. I had to edit the file ".npmrc" which will be under user home directory (ex: c:\users\abcuser) :
http_proxy=null
registry=https://registry.npmjs.org/
strict-ssl=true
proxy=null
This works
npm config delete http-proxy
npm config delete https-proxy
npm config rm proxy
npm config rm https-proxy
set HTTP_PROXY=null
set HTTPS_PROXY=null
Running npm version 2.10.1 in windows 7, I used:
npm config delete proxy
npm config delete https-proxy
Try This,
npm config delete http-proxy
npm config delete https-proxy
npm config rm proxy
npm config rm https-proxy
set HTTP_PROXY=null
set HTTPS_PROXY=null
The easiest way to remove any configuration at all from npm is to edit the npm config file. It only takes two(2) commands to do this; one to open npm config file for editing, the other to confirm your change.
type npm config list to view a list of all npm configurations that are active.
type npm config edit to open a text editor with npm configurations.
To remove the proxy line ( or simply comment it out ).
Save the config file and close it.
type npm config list to confirm that the proxy configuration has been removed.
C'est la vie!
I tried everything listed on this page, none worked, then I tried to the config edit. It worked instantly. (I use Windows 10)
npm config delete proxy -g
worked for me.
-g was important as initially it was set with that option.
You can check configurations set with :
npm config list
npm config rm proxy
npm config rm https-proxy
Worked for me
I think it's not http-proxy but proxy:
npm config set proxy="http://yourproxyhere"
Got exactly the same problem, I keep seeing my proxy configuration even after removing the npmrc file and deleting the keys.
I found out that npm were using windows env key http-proxy by default.
So go in Computer->Properties->Advanced system settings->Environement variables and check there is no http-proxy key configured.
In my case (Linux Mint 16 based on Ubuntu), I had to:
npm config delete https-proxy, and also
clear the https_proxy Bash environment parameter — oddly enough, although I cannot find this behavior documented anywhere, npm fallbacks to https_proxy:
$ http_proxy='' https_proxy='' npm config get https-proxy
null
$ http_proxy='' xxhttps_proxy='' npm config get https-proxy
https://1.2.3.4:8080
See the npm Settings in file C:\Users\myusers.npmrc file. Sometime the npm proxy config settings does not apply. so its worth checking in there.
npm config delete http-proxy
npm config delete https-proxy
npm config delete proxy -g
npm config delete http-proxy -g
then
npm config get proxy
null
also
npm i -g bower to update
npm had a bug on the proxy
If you want to switch between proxy for company network and remove proxy for home/personal network you can use --no-proxy
Sample usage:
npm install --save-dev "#angular/animations#8.2.14" --no-proxy
execute npm config list
it will list down all proxy values.. in my case proxy value was fetched form global npmrc file, removed it and was able to complete npm install on my windows machine
Well, I'm gonna leave this here because I was having a big trouble with NPM.
I was trying to change a proxy setting using npm config set proxy "http://.../" and then running npm config get proxy. It was ALWAYS returning a wrong value, different from the one that I'd set.
I found out that I had a .npmrc COMMITED on the project I was trying to run npm install and that this file was overriding my own config.
So it was cleaning the proxy value, but I needed to also change the .npmrc inside the folder's project.
After that, everything worked fine.
I've used
npm config set proxy null
npm config set https-proxy null
and it worked for me.
Best regards
this works for me fime
proxy=http://<username>:<pass>#proxyhost:<port>
https-proxy=http://<uname>:<pass>#proxyhost:<port>
sample in my instance username:uname and password:pword
npm config set proxy=http://uname:pword#192.168.5.8:8080
npm config set https-proxy=http://uname:pword#192.168.5.8:8080
I was struggling with this for ages. What I finally did was go into the .npmrc file (which can be found in the user's directory followed by the user's name, ie. C:\Users\erikj/.npmrc), opened it with a text editor, manually removed any proxy settings and changed the http:// setting to https://. In this case, it is a matter of experimenting whether http or https will work for you. In my case, https worked. Go figure.
In my case, (windows OS), after put all those commands listed, npm kept taking
the proxy in the setting of windows registry
\ HKEY_CURRENT_USER \ Environment
just remove the proxy settings there, after that, I restarted the pc and then "npm install" worked for me
Example
Http Module is deprecated and it is replaced with HttpClient.
Change your imports to import { HttpClientModule } from '#angular/common/http';

How to restore/reset npm configuration to default values?

I have played with npm set and npm config set for several times, now I want to reset to default values (a kind of factory reset).
Does npm provide a command to do that? Or should I delete all configuration files by hands then reinstall it?
I need to do it both on Linux CentOS and on Windows 8.
To reset user defaults
Run this in the command line (or git bash on windows):
echo "" > $(npm config get userconfig)
npm config edit
To reset global defaults
echo "" > $(npm config get globalconfig)
npm config --global edit
If you need sudo then run this instead:
sudo sh -c 'echo "" > $(npm config get globalconfig)'
For what it's worth, you can reset to default the value of a config entry with npm config delete <key> (or npm config rm <key>, but the usage of npm config rm is not mentioned in npm help config).
Example:
# set registry value
npm config set registry "https://skimdb.npmjs.com/registry"
# revert change back to default
npm config delete registry
If you run npm config edit, you'll get an editor showing the current configuration, and also a list of options and their default values.
But I don't think there's a 'reset' command.
If it's about just one property - let's say you want to temporarily change some default, for instance disable CA checking: you can do it with
npm config set ca ""
To come back to the defaults for that setting, simply
npm config delete ca
To verify, use npm config get ca.
npm config edit
Opens the config file in an editor. Use the --global flag to edit the global config.
now you can delete what ever the registry's you don't want and save file.
npm config list will display the list of available now.
Config is written to .npmrc files so just delete it. NPM looks up config in this order, setting in the next overwrites the previous one. So make sure there might be global config that usually is overwritten in per-project that becomes active after you have deleted the per-project config file. npm config list will allways list the active config.
npm builtin config file (/path/to/npm/npmrc)
global config file ($PREFIX/etc/npmrc)
per-user config file ($HOME/.npmrc)
per-project config file (/path/to/my/project/.npmrc)

Unset core.editor in Msysgit

I set my editor per an SO entry: How do I setup DiffMerge with msysgit / gitk?.
I'm wondering how to undo this because I want to switch back to the default editing program.
Depending on how you ran git config...
git config --unset core.editor
Or
git config --global --unset core.editor

Resources