title: NPM post-install, CA certificates, and Windows
body: <h3>TLDR;</h3>
  
  <p>Is it possible, in a Windows environment, to set <code>NODE_EXTRA_CA_CERTS</code> in a way that works with NPM packages' post-install scripts, without making system changes, configuration file changes, or changes that require admin-level permissions?</p>
  
  <h3>Details</h3>
  
  <p>This has been driving me nuts.</p>
  
  <p>I added image optimization to our Webpack build process via imagemin, imagemin-webpack, and the various imagemin format-specific plugins.</p>
  
  <p>All of the imagemin plugins have one thing in common -- during post-install, they: </p>
  
  <p>a. Attempt to download a pre-built EXE.<br>
  b. If (a) fails, they attempt to build the EXE from source.</p>
  
  <p>I.T. snoops on our traffic, so (a) fails due to the "self-signed certificate in chain" error when attempting to fetch the remote EXE. (b) fails because our studio is Windows-based, and we don't have all the various build tools installed to make that happen. It's also not reasonable to have them installed on every machine where <code>npm install</code> might be run.</p>
  
  <p>I did some digging (thanks S.O.), found our company's CA certificate, added it to the repo, and was able to get (a) working with the following commands:</p>
  
  <pre><code>&gt; SET NODE_EXTRA_CA_CERTS=%cd%\ca.cert
  &gt; npm install
  </code></pre>
  
  <p>I thought I was home free at that point -- all I'd have to do is add this npm script to our package.json:</p>
  
  <pre><code>{
    "preinstall": "SET NODE_EXTRA_CA_CERTS=%cd%\\ca.cert"
  }
  </code></pre>
  
  <p>But that doesn't work. I'm guessing it's because there's a separate process involved, and the environment variable doesn't carry over to the other process.</p>
  
  <p>Note that this <em>does</em> work, but is absolutely awful:</p>
  
  <pre><code>{
    "preinstall": "SET NODE_EXTRA_CA_CERTS=%cd%\\ca.cert&amp;&amp; npm install imagemin-gifsicle imagemin-mozjpeg imagemin-optipng imagemin-svgo"
  }
  </code></pre>
  
  <p>Is there a way to set this environment variable automatically in a way that works with NPM packages' post-install scripts?</p>
  
  <p>I'd like this to be transparent to other team members so that they can just continue to <code>npm install</code> without any additional steps, system changes, or configuration file changes if at all possible. Some team members are not developers, so while they're used to running <code>npm install</code>, I don't want to introduce any additional complications. I super appreciate any help in advance!</p>