Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed REST APIs with Express!
You have completed REST APIs with Express!
Preview
We can use JavaScript's async/await keywords to handle asynchronous actions in our code, to make sure we have our quotes data before we respond to the client.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
records.getQuotes reaches into our data
store, gets all of the quotes, and
0:00
returns them to us.
0:01
Once we have all those quotes,
we send them back to the client as JSON.
0:02
At the moment, however,
we're getting back an empty object.
0:06
And this is because the getQuotes
function is asynchronous.
0:09
All the functions in the records.js
module use asynchronous functions to
0:13
closely mimic the behavior
of an actual database.
0:18
And accessing a database is
an inherently asynchronous operation,
0:21
meaning we can't be exactly sure when
we're going to receive the information.
0:25
And in the meantime, JavaScript just
keeps on going without waiting for
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up