Set environment variables in npm scripts
Switch branches/tags
Nothing to show
Clone or download

You might actually want to look at my other utility cross-env. It's probably what you're really looking for :-)


Status: npm version npm downloads Build Status Code Coverage js-standard-style

Use in your config files to set environment variables cross-platform.


I use this with my npm scripts:

  "scripts": {
    "build": "webpack --set-env-NODE_ENV=production",
    "test": "karma start --set-env-COVERAGE=true --set-env-NODE_ENV=test"

And then in my webpack.config.js file, at the very top I do:


Which in the case of build would set NODE_ENV to the string 'production' and in the case of test it would set NODE_ENV to the string 'test' and COVERAGE to the boolean true.


You can optionally pass options:

  // I'm setting these to the defaults here
  // you could set them to whatever you want
  env: process.env, // the object to have variables set on
  argv: process.argv, // the array of arguments which have the arguments defined
  prefix: '--set-env', // the prefix used in the array of arguments defining variables to set