Last active
September 21, 2017 10:04
-
-
Save damieng/0cffc846cb6be386babcf0a606e36dc6 to your computer and use it in GitHub Desktop.
Apply Windows proxy settings to npm automatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
$proxyKey = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyServer -ErrorAction Stop).ProxyServer | |
foreach($proxy in $proxyKey.Split(';')) { | |
$parts = $proxy.Split('=') | |
switch ($parts[0]) { | |
'http' { iex "npm config set proxy http://$parts[1]"; break } | |
'https' { iex "npm config set https-proxy http://$parts[1]"; break } | |
} | |
} | |
} | |
catch { | |
# No config was found - no proxy! | |
iex "npm config delete proxy" | |
iex "npm config delete https-proxy" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment