"Build a Simple Ruby on Rails Application" was retired on September 16, 2016.
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 Asynchronous Code in Express!
You have completed Asynchronous Code in Express!
An example of using promises to handle asynchronous tasks in Express.
An example of what using promises to perform two asynchronous operations might look like:
app.get('/:id', (req, res) => {
getUser(req.params.id)
.then((user)=>{
return getFollowers(user);
})
.then((user, followers)=>{
res.render('profile', {title: "Profile Page", users: user, followers: followers});
})
.catch((err) => {
res.render('error', {error: err});
});
});
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
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