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?
For the windows users, you may use your variables like this: %SERVER%
instead of $SERVER
.
Or better approach to use cross-env
module which will allow you to do it like linux on all platforms:
npm i cross-env
And use it :
"scripts": {
"test": "cross-env-shell \"istanbul cover node_modules/.bin/_mocha --root ../$SERVER/routes -- --recursive\""
}
使用$SERVER
对你$SERVER
吗?
"scripts": { "test": "istanbul cover node_modules/.bin/_mocha --root ../$SERVER/routes -- --recursive" }
It would be better to use env
and get the value inside the script with process.env
instead. It's a widely used practice.
package.json
is just a json file, it even doesn't allow comments, so I'd not suggest to use this approach.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.