Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
An example of using callbacks to handle asynchronous tasks in Express.
Example of a callback with performing two asynchronous operations:
app.get('/:id', (req, res) => {
getUser(req.params.id, (err, user)=>{
if(err){
res.render('error', {error: err});
} else {
getFollowers(user, (err, followers) =>{
if(err){
res.render('error', {error: err});
} else {
res.render('profile', {title: "Profile Page", user: user, followers: followers});
}
});
}
});
});
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Maximilian Skjønhaug
4,637 Points1 Answer
-
karan Badhwar
Web Development Techdegree Graduate 18,135 Points1 Answer
-
weinian he
Full Stack JavaScript Techdegree Graduate 17,167 Points1 Answer
-
babyoscar
12,930 Points3 Answers
-
Will Albertsen
13,155 Points2 Answers
-
Adam Lyles Kauffman
14,016 Points4 Answers
View all discussions for this video
Related 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