node.js - How do you access flags passed in through the command line in Node? -


i know access them in process.argv. ex.

~/code/study-buddies $ node server/app.js --dev [ 'node',   '/users/azerner/code/study-buddies/server/app.js',   '--dev' ] 

but best practice? if want access array of flags, not normal command line arguments?

"best practice" relative question , i'm not sure mean "the normal command line arguments" stuff can found in other people have done in past.

for example, can @ minimist see 1 way arguments handled. initial example pretty simple: pass argv array module , parses receives.

var argv = require('minimist')(process.argv.slice(2));

the module loops through argument array, parsing out , building object can used without worrying quite fiddly bits of argv parsing.

other modules, node-getopt , commander.js provide ton more functions, in end relying upon argv


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -