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
From the course: Building Your First CLI App in Node
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Understand user prompts1m 46s
-
(Locked)
Create a prompt for user input2m 24s
-
(Locked)
Validate user input1m 53s
-
(Locked)
Store GitHub credentials for reuse3m 2s
-
(Locked)
Receive the GitHub token3m 39s
-
(Locked)
Authenticate with GitHub2m 29s
-
(Locked)
Register a new token3m 23s
-
(Locked)
Implement the GitHub token3m 31s
-
-
-
-