concept callback function in category node

This is an excerpt from Manning's book Get Programming with Node.js.
In this code example, I use ES6 syntax to assign the variable printNumbers to a function defined with a single arr parameter and an arrow symbol in place of the traditional function keyword. I use another arrow function as the callback function within my forEach call.
Move your route callback functions to the home controller, and add them to that module’s exports object. Your route to respond with a vegetable parameter, for example, can move to your home controller to look like listing 9.6. In homeController.js, you assign exports.sendReqParam to the callback function. sendReqParam is a variable name, so you can choose your own name that describes the function. Listing 9.6. Moving a callback to homeController.js
exports.sendReqParam = (req, res) => { 1 let veg = req.params.vegetable; res.send(`This is the page for ${veg}`); };
- 1 Create a function to handle route-specific requests.
To follow the MVC design pattern, move your callback functions to separate modules that reflect the purposes of those functions. Callback functions related to user account creation, deletion, or changes, for example, go in a file called usersController.js within the controllers folder. Functions for routes that render the home page or other informational pages can go in homeController.js by convention. Figure 9.2 shows the file structure that your application will follow.

This is an excerpt from Manning's book Getting MEAN with Mongo, Express, Angular, and Node.js 2ED.
The exec method executes the query and passes a callback function that will run when the operation is complete. The callback function should accept two parameters: an error object and the instance of the found document. As it’s a callback function, the names of these parameters can be whatever you like.
Callbacks are typically used to run a piece of code after a certain event has happened. Whether this event is a link being clicked, data being written to a database, or another piece of code finishing executing isn’t important, as the event could be almost anything. A callback function itself is typically an anonymous function—a function declared without a name—that’s passed directly to the receiving function as a parameter. Don’t worry if this seems like jargon right now; we’ll look at code examples soon, and you’ll see how easy it is.