Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a REST API With Express Communicating with Mongo through Mongoose Extending Mongoose

Kevin S
seal-mask
.a{fill-rule:evenodd;}techdegree
Kevin S
Data Analysis Techdegree Student 15,862 Points

What is the "callback" parameter doing?

Hi all,

When the instance method is created to update the answer, what is the purpose of the callback parameter that is part of AnswerSchema.method? Andrew said that it is for when the operation is completed, but I don't really see why it is needed. Anyone else confused by this? Thanks!

2 Answers

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

The callback to this update method is a function that you'll pass in later when you call it. In the next video at 16:44 on line 72 you can see here we're now calling this update method and passing in a callback. This is telling it what to do when it finishes the update, in this case either throw and error or return the json to the client.

I'm very much looking forward to the refresh of this course coming soon. I'm hoping it will use promises rather than callbacks, and I'm also hoping it will use a relational database and Sequelize as opposed to Mongo and Mongoose. (Others might disagree but it seems like NoSQL was a little overhyped and is retreating to narrower use cases..)

Then today Treehouse changed techdegree curriculum, has no more non-relational project, now students use SQL.