January 2018
Beginner
658 pages
13h 10m
English
The last thing I want to discuss before we wrap up this section is—how we fetch command.
As we know, command is available in the _ property as the first and only item. This means that in the app.js, var command statement, we can set command equal to argv, then ._, and then we'll use [] to grab the first item in the array, as shown in the following code:
console.log('Starting app.js');const fs = require('fs');const _ = require('lodash');const yargs = require('yargs');const notes = require('./notes.js');const argv = yargs.argv;var command = argv._[0];console.log('Command:', command);console.log('Yargs', argv);if (command === 'add') { notes.addNote(argv.title, argv.body);} else if (command === 'list') { notes.getAll();} else ...