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 - Node.js Tutorial
From the course: Node.js Essential Training
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…
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
-
-
-
-
Inspecting the global object3m 46s
-
(Locked)
Using the require function3m 4s
-
(Locked)
Handling argument variables with process.argv3m 29s
-
(Locked)
Working with standard input3m 37s
-
(Locked)
Using standard output3m 13s
-
(Locked)
Creating a delay with setTimeout2m 3s
-
(Locked)
Incorporating setInterval2m 51s
-
(Locked)
Reporting progress with setInterval1m 43s
-
-
-
-