I am learning how to use node.js, but am having trouble parsing command-line arguments. The following line:
node test.js --input=in.txt
Gives a parsing error when the code reaches this command:
var fileName = JSONparse.(process.argv[2]);
Results in the error:
undefined
--input=in.txt
Syntax error: Unexpected number
What I am trying to do is create an optional variable for the input file. If it is not specified in the command-line, it should resolve to 'a.txt'.
I have not found an easy way of creating default parameters, or use identifiers such as '--input=' to not have to worry about the order in which arguments are passed (I know it does not matter in this case with one argument).
Vorpal.js is a framework I made for building interactive CLIs in Node. As part of this, it has a built-in API for easy command parsing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With