Passing empty arguments to title and body

In one of the lessons to configure yargs, there was a suggestion to use ‘string’ object as a property to the option ‘address’ to prevent passing empty arguments (which might be considered a boolean by yargs).

I was elated to find that such an option exists because earlier when I ran the notes app in it’s final form, I could still run a command like
node app.js add --title --body
And this would run successfully, returning,

Note created
--
Title:
Body:

It was a design flaw, just specifying demand: true did not help. It just asserted the occurrence of --title and --body properties in the argv object.

So, I went on to edit my app.js file on the note-node app, and added string : true option to both title and body. But this did not work either. The app is till creating empty notes.

Attaching the output from my terminal (after making changes to app.js) for your reference.

What you are looking for is the requiresArg: true option. Adding this will require the address option to be specified with a value, so an empty string will not be allowed.

Specifying string: true just causes the address argument to be treated as a string. As you noticed, an empty string is still allowed.

The instructions were slightly confusing regarding this, so I updated them to make them clearer. I also added information about the requiresArg option since that is a useful option. Thanks for letting us know about this and let us know if you have any more questions or run into any more issues!

1 Like

Thanks, it worked! :smile:

1 Like