P
P
Philip2017-12-01 02:18:27
JavaScript
Philip, 2017-12-01 02:18:27

Need to split and assign variables given on the command line?

Query example: I found out that process.argv stores all options given on the command line. But I can't figure out how to take values ​​from process.argv and assign them to DIR and PATTERN. Also, according to the task, the order of the parameters can be different.
node index.js --DIR="/Downloads" --PATTERN=\.js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2017-12-01
@k12th

https://www.npmjs.com/package/minimist or https://www.npmjs.com/package/yargs
What's the problem anyway? We go around the process.argv array starting from the second element, and see what lies there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question