DEV Community

Discussion on: Creating a command-line app in Node.js: Argument Parsing

Collapse
 
elaspog profile image
László Pogány

UPDATE:

  • while experimenting with this library I've found out, that "name" is not a good choice as name of the parameter, because there is an inner private function (_name) used by this library which gives back the script name.

console.dir(commander)
// ..
_args: [],
_name: 'index',
_optionValues: {},
//...

If you call this function it gives back the filename

console.log(commander.name());
// index

That's the reason why this happens if you run the script from console with "demo" parameter:

$ node index.js demo
Your name is function(str) {
if (arguments.length === 0) return this._name;
this._name = str;
return this;
}.
This is a DEMO.