From the course: Node.js Essential Training
Unlock the full course today
Join today to access over 24,300 courses taught by industry experts.
Creating a delay with setTimeout - Node.js Tutorial
From the course: Node.js Essential Training
Creating a delay with setTimeout
- [Instructor] In the last lesson, we used Node.js asynchronously by using event listeners. So what we said here was instead of just running the functions when they are added to our JavaScript file, we said only call the function that's sent to this function when we have a data event, and only send this function when we have an exit event. So call these functions at specific times. Now, another way that we can work with Node.js asynchronously is through timing functions. So the timing functions like set timeout, clear timeout, set interval, and clear interval work the same way that they do in the browser, and are available to us globally. So let's go ahead and create a set timeout function. We're going to create a new variable here called waitTime. So we'll say const waitTime. And we'll set that to 3,000, which means three seconds or 3,000 milliseconds. Then we're going to call a console log, and we'll say setting a…
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
-
-
-
-