0

What is the differences of var argv = require("yargs") and var argv = require("yargs").argv? Into variable argv how the same time that i require a package, there are all functions/modules of package but .argv what is it?

Thanks all Morris

Morris
  • 601
  • 1
  • 8
  • 22

1 Answers1

2

require('yargs') loads the yargs module whih will immediately parse command line options for you. .argv will contain the options and values the user passes. You could also write it as :

const yargs = require ('yargs')
const argv = yargs.argv
Tom Jardine-McNamara
  • 2,418
  • 13
  • 24
  • Maybe i understand. So, when i write: 'var command = argv._[0]' , with 'argv i call my variable that contain the package and when i use '._[0] ' i go into '.argv' for access the options and value the user passes and read command on [0] position. – Morris Oct 13 '16 at 09:09
  • 2
    Correct, named options will be properties on `argv` and positional args will be listed in order on `argv._`. You can use positional args for commands, but you're much better of using yargs' built in command support. You can also define help messages and examples for each of your options, and a whole lot more - you should check out their excellent (if rather long) documentation. Here's a good example of some of the features in use: https://www.npmjs.com/package/yargs#yargs-is-here-to-help-you – Tom Jardine-McNamara Oct 13 '16 at 10:38
  • Perfect. Thank you so much :) – Morris Oct 13 '16 at 10:41