Skip to content

Instantly share code, notes, and snippets.

@alienlebarge
Last active March 20, 2023 10:16
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save alienlebarge/10260853 to your computer and use it in GitHub Desktop.
Save alienlebarge/10260853 to your computer and use it in GitHub Desktop.
Setting proxy with node.js

Node.js behind a proxy

Write proxy settings

$ npm config set proxy http://localhost:3128
$ npm config set https-proxy http://localhost:3128

This config is great for SquidMan app.

Delete proxy settings

$ npm config delete http-proxy
$ npm config delete https-proxy
@alienlebarge
Copy link
Author

@haxpor
Copy link

haxpor commented Mar 2, 2017

Is this also for nodejs application (I read the title) or just for npm to manage package?

@timbophillips
Copy link

note: nodejs itself uses the command line proxy settings.

http_proxy
Specify the value to use as the HTTP proxy for all connections. For example, HTTP_PROXY=“http://proxy.mycompany.com:8080/”.
https_proxy
Specify the value to use as the HTTPS proxy for all connections. For example, HTTPS_PROXY=“https://proxy.mycompany.com:8080/”.
no_proxy
Determine hosts that should bypass the proxy. For example, NO_PROXY=”localhost,.mycompany.com,192.168.0.10:80”

@ghosty-be
Copy link

timbophilips ... this is the solution to hours wasted!
Thx for this remark!
Trying to setup rocketchat behind a proxy and the command "n 8.9.4" just errors out with "Error: invalid version 8.9.4"
Was looking in the proxy logs what url it tried to access (since we work with restrictive whitelists) but couldn't see it go anywhere...
This error reporting is useless and belongs to the "How To Make Package Managers Cry" talk presented few weeks ago at FOSDEM
Could have saved me a couple hours of agitation if it only said "can't reach url x"

@boegel
Copy link

boegel commented Mar 11, 2018

@ghosty-be: +1: ;)

@gajus
Copy link

gajus commented Apr 25, 2019

note: nodejs itself uses the command line proxy settings.

Contrary to what @timbophillips said, Node.js does not use HTTP_PROXY environment variables. See this discussion nodejs/node#8381.

To set a global Node.js proxy use https://github.com/gajus/global-agent.

@jselbie
Copy link

jselbie commented Aug 18, 2019

Why it is npm config set proxy http://localhost:3128 for setting the property, but the unsetting of this property is documented as npm config delete http-proxy ? Is this a typo ?

@andig
Copy link

andig commented Apr 22, 2021

Does this config even apply to node or just to npm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment