title: How do I use value of env variable in npm script?
body: <p>I want to set and use an env variable in npm script. The reason for doing so is that our npm package will get built in CI pipeline, and CI machines have predefined env variables for artifacts/coverage/test paths. In developer's local machines, those paths don't exist so need a default value. </p>
  
  <pre><code>"scripts": {
      "test": "COVERAGE_PATH=${COVERAGE_PATH:-./build/coverage} istanbul cover --dir ${COVERAGE_PATH} --include-all-sources tape -- tests/*.js",
      "build": "ARTIFACTS_PATH=${ARTIFACTS_PATH:-./build/} browserify -r ./index.js &gt; ${ARTIFACTS_PATH}/bundle.js",
  }
  </code></pre>
  
  <p>On local machine ($COVERAGE_PATH is not defined here so fallback value will be used), when I run <code>npm run test</code> , the coverage gets generated and put in a directory named <code>--include-all-sources</code>. Essentially when npm runs the script command, it ignores the value of <code>${COVERAGE_PATH}</code>. I tried changing it to <code>`echo $COVERAGE_PATH`</code> in the npm script, but still same result. </p>
  
  <p>I even tried defining the variables in my shell beforehand before running the npm run script command, but any <code>${VAR}</code> in the script still does not get replaced. How do I get the value of env variables to be correctly replaced in npm scripts.</p>
  
  <p>EDIT:<br>
  To make it clear, I want to know how to get correct variable value replaced in following cases:</p>
  
  <ol>
  <li><code>VAR=build node ${VAR}/app.js</code></li>
  <li><code>SOMEVAR=build
  node ${SOMEVAR}/app.js</code></li>
  </ol>