Skip to content

Instantly share code, notes, and snippets.

@damieng
Last active September 21, 2017 10:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save damieng/0cffc846cb6be386babcf0a606e36dc6 to your computer and use it in GitHub Desktop.
Save damieng/0cffc846cb6be386babcf0a606e36dc6 to your computer and use it in GitHub Desktop.
Apply Windows proxy settings to npm automatically
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