From the course: Building Your First CLI App in Node

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Validate user input

Validate user input

From the course: Building Your First CLI App in Node

Start my 1-month free trial

Validate user input

- [Instructor] One other thing we can do is be sure that the user has entered information in the appropriate fields. So we can just validate this. On the line immediately after your enter username line, create another object called validate. This will create a function that checks the user's entered input just to be sure that an input has been given. So that argument is going to be value. And basically what we have to do is much like what we did earlier. And we're just going to check the length here of how many values were passed in. If more than zero things were entered then this should return true. Otherwise if we haven't received any input from the user, let's return a message to them that just asks them to try again. Below our username function, you're going to build the same structure for the password question. Let's just make sure to put a comma here after this squiggly bracket that's beside your square bracket. Bring that square bracket down to the end, and open new brackets…

Contents