Search code examples
node.jsminimist

How to get index of command line arguments passed when process was launched?


For example: node app.js --help --path=asd

I want to know index of --help argument to be sure that it a first.

Minimist returns an object which keys are these arguments, but we cann't be sure of the order of the keys of the object.

I see only one solution:

if (process.argv[2].indexOf('--help') === 0 || process.argv[2].indexOf('-h') === 0 ) {...}

Solution

  • If there is no ready-made solution, so:

    if (process.argv[2].indexOf('--help') === 0 || process.argv[2].indexOf('-h') === 0 ) {...}