Home  >  Q&A  >  body text

Is there a way to make npm install (command) work behind a proxy?

<p>Read the proxy variable in the <code>.npmrc</code> file but it doesn't work. Try to avoid manually downloading and installing all required packages. </p>
P粉743288436P粉743288436445 days ago590

reply all(1)I'll reply

  • P粉775723722

    P粉7757237222023-08-24 16:51:53

    I solved the problem like this:

    1. I run this command:

      npm config set strict-ssl false
      
    2. Then set npm to run using http instead of https:

      npm config set registry "http://registry.npmjs.org/"
      
    3. Then I install the package using the following syntax:

      npm --proxy http://username:password@cacheaddress.com.br:80 install packagename
      

    If the proxy does not require you to authenticate, skip the Username:Password section

    EDIT: A friend of mine just pointed out that you can get NPM to work behind a proxy by setting the BOTH HTTP_PROXY and HTTPS_PROXY environment variables and then issuing the command normally npm install express(for example)

    Edit 2: As @BStruthers commented, please remember that passwords containing "@" will not parse correctly, if it contains @, put the entire password in quotes

    reply
    0
  • Cancelreply