title: How to set env var for .npmrc use
body: <p>I need a module in my project to download a private npm package. To accomplish this, I am using a <code>.npmrc</code> file to supply a read-only token needed to download the package. To keep the token supplied by npm out of the file, I wish to add it as an environment variable and let it expand in the file. E.g:</p>
  
  <pre><code># .npmrc
  //registry.npmjs.org/:_authToken=${NPM_TOKEN}
  </code></pre>
  
  <p>I can't figure out how to get that <code>NPM_TOKEN</code> added to the env before it is referenced for the install. I tried using an npm preinstall script:</p>
  
  <p><code>"preinstall": "NPM_READ_ONLY_TOKEN=my_token_goes_here_foo_bar"</code>**</p>
  
  <p>But I still get the same error: </p>
  
  <pre><code>Error: Failed to replace env in config: ${NPM_READ_ONLY_TOKEN}
  </code></pre>
  
  <p>I tried testing with an echo command to see if <code>preinstall</code> runs before the .npmrc variable expansion, but it apparently does not. I would get the error and not see my echo log. I seem to be missing something here.</p>
  
  <p>I'm aware that putting my token in package.json defeats the purpose of pulling the token out of the .npmrc file. I'm actually using a service that provides env config services that I would use to run a command and get the needed token. E.g. <code>TOKEN=config_service_value</code>.</p>