From the course: Node.js Essential Training
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Reporting progress with setInterval - Node.js Tutorial
From the course: Node.js Essential Training
Reporting progress with setInterval
- [Narrator] So let's for the fun of it add one more thing. We're going to add this to our increment time function. So right underneath where we're saying current time and wait interval, we're going to create a value called p, and we're going to set that equal to Math.floor. Inside of this we're going to take our currentTime divided by our waitTime. We're going to multiply that by 100. And then we're going to say process.standard output.clearLine. We're going to say process, standard, output.cursorTo and we'll set the cursor to zero. So that first position will get rid of our other console message. And here we'll say process, standard output.right, waiting. And then we'll use that p value that we've set here. Let's go ahead and run it one more time. So now we see the waiting communicated as a percentage in place, and that's because standard output gives us the tools to manage how we write all of this data to the console.…
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
-
-
-
-