title: nodejs environment variable "NODE_EXTRA_CA_CERTS"
body: <p>I am developing a mobile application based on Ionic + Angular + Cordova + Node js. </p>
  
  <p>the application visits a https server via window.XMLHttpRequest:  </p>
  
  <pre><code>module.exports = function request (method, url, body, headers) {
    return new Promise(function (resolve, reject) {
      var xhr = new window.XMLHttpRequest()
  
      xhr.open(method, url)
  
      xhr.onload = function () {
        return resolve({
          status: xhr.status,
          body: xhr.responseText
        })
      }
  
      xhr.onerror = xhr.onabort = function () {
        return reject(new Error(xhr.statusText || 'XHR aborted: ' + url))
      }
  
      Object.keys(headers).forEach(function (header) {
        xhr.setRequestHeader(header, headers[header])
      })
  
      xhr.send(body)
    })
  }
  </code></pre>
  
  <p>for this function to be executed, an appropriate root CA need to be inserted into node environment.
  since I do not control the code that makes the https request, I would prefer a policy/config based approach that enables an extra root CA into node js. </p>
  
  <p>I searched around, and found out that node had actually provided a environment variable '<a href="https://nodejs.org/api/cli.html#cli_node_extra_ca_certs_file" rel="noreferrer">NODE_EXTRA_CA_CERTS</a>' that seems to meet my purpose. </p>
  
  <p>yet I can not find any examples on how to utilize this variable. </p>
  
  <p>my implementation is to install the npm package <a href="https://www.npmjs.com/package/dotenv-webpack" rel="noreferrer">dotenv-webpack</a>.</p>
  
  <p>added a .env file which contains configuration 'NODE_EXTRA_CA_CERTS=./assets/cert/cacert.pem' (file path to the appropriate root CA).</p>
  
  <p>I can verify that the variable NODE_EXTRA_CA_CERTS had been successfully set. yet it did not seem to have any effects. the access to the server was denied because of security.</p>
  
  <p>so my question: can anyone please provide an example on how to utilize the variable 'NODE_EXTRA_CA_CERTS'?</p>
  
  <p>thanks </p>