From the course: Node.js Essential Training

Unlock the full course today

Join today to access over 24,300 courses taught by industry experts.

Using standard output

Using standard output

- [Instructor] So with our file, we want to change the code a bit to collect answers from our terminal. So the first thing we want to do is let's make sure to move our ask function above our process standard input. Another thing I'm noticing here is that this is looking for answers.length. If we wanted to set this to be an empty array, we could always add a default here. So we could add a default argument to this function and remove this from our function invocation here. So that's one thing we can do. The second thing I want to do is instead of echoing the answer back out, let's go ahead and add this to the array. So we're going to replace process standard input.write with answers.push. We'll take data, convert it to a string and trim off any white space. The next thing we want to do is say if our answers.length is less than our questions.length, then we want to call the ask function again with answers.length. So…

Contents