Anubhav Dhawan Anubhav Dhawan - 1 month ago 17
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
SERVER
variable in the npm script in the package.json itself?

Answer

Will using $SERVER work for you?

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

Comments