I am writing test cases for my Node.js application using Mocha. The test cases need an API key as an extra input option or parameter. The API key is private, so I don\'t wan
One of the easiest ways to pass parameters similar to the process.argv[index] method mentioned in this thread is using the npm config variables. This allows you to see the variable name a little more clearly:
test command:
npm --somevariable=myvalue run mytest
package.json:
"scripts": {
"mytest": "mocha ./test.js" }
test.js
console.log(process.env.npm_config_somevariable) // should evaluate to "myvalue"