args-parser
Straight-forward node.js arguments parser.
Get the module
$ npm install args-parser
How to use it?
args(arguments)
Simply call the module passing it an arguments
array such as process.argv
:
const args = require("args-parser")(process.argv)
console.info(args)
The returned value is an Object
having a key for each argument given, and eventually a value if it's found an =
sign.
Considering that simple command:
$ node ./script.js careful -dangerous --tomatoes=3 --tonight
Will return:
{
"careful": true,
"dangerous": true,
"tomatoes": 3,
"tonight": true
}
So then you can easily check what you need:
if (args.careful) {
}