Specify optimist / minimist command line options which are equally available to Node app whether executed via Node, Nodemon or Istanbul/Mocha

StackOverflow https://stackoverflow.com/questions/22277865

Question

So I have a number of methods by which I run my node app:

Production, and running for WebDriver tests:

node app.js

Development

nodemon app.js

Mocha tests

istanbul cover node_modules/mocha/bin/_mocha -- -R spec

I'd like to use Optimist / Minimist module to handle command line options however, is there any way to provide those arguments to all of the above commands in a way that is consistently handled by my app?

Était-ce utile?

La solution

After a bit more digging I finally got the answers.

Nodemon will pass on all arguments as is:

nodemon app.js --env=dev

Mocha will do the same, however you must specify a filename after spec or else it tries to interpret the command line args itself. So even though mocha defaults to test/test.js, specifying this allows command line args to pass to the app:

istanbul cover node_modules/mocha/bin/_mocha -- -R spec test/test.js --env=test
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top