Anubhav Dhawan Anubhav Dhawan - 5 months ago 44
Node.js Question

How to get environment variable in npm script?

I am trying to access an enviroment variable in the npm script itself like so:

"scripts": {
"test": "istanbul cover node_modules/.bin/_mocha --root ../SERVER/routes -- --recursive"

And start this script like so:

SERVER=somewhere npm test

How can I get the resolved value of
variable in the npm script in the package.json itself?


Will using $SERVER work for you?

"scripts": { "test": "istanbul cover node_modules/.bin/_mocha --root ../$SERVER/routes -- --recursive" }