0

I want to set process.env.ENV as TEST or null using a script from package.json but below command is not working via package.json (it works when I run it directly on cmd.).

script { "start": "cross-env ENV=null && node app.js", "test": "cross-env ENV=TEST && istanbul cover mocha test" }

I am using corss-env to use a common syntax for setting up env variable for Windows and Linux.

Running set ENV=TEST or set ENV=null before npm start or npm test work fine.

mehtak
  • 137
  • 1
  • 14

1 Answers1

1

You don't need && in scripts

try

"scripts": {
  "start": "cross-env ENV=null node app.js",
  "test": "cross-env ENV=TEST istanbul cover mocha test"
}
Manan Vaghasiya
  • 881
  • 1
  • 10
  • 25
  • Thanks, this worked. Further, what commands need && and what not? – mehtak Mar 13 '17 at 12:34
  • 1
    you use && when you need to run second command after the first ran successfully. Setting env variable before running command like above itself is not really a command, so no need to use &&. Also see http://stackoverflow.com/questions/7128542/how-to-set-an-environment-variable-only-for-the-duration-of-the-script – Manan Vaghasiya Mar 13 '17 at 12:46