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.

1 Answer 1

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"
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, this worked. Further, what commands need && and what not?
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 stackoverflow.com/questions/7128542/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.