O'Reilly logo
  • Patrick S thinks this is interesting:

It's a common practice to modify the request or the response objects because they are the input and output of the module. We can attach new properties or functions, and they will be available for the next middleware in the list. As in the following code snippet, we are attaching an object to a data property.

.use(function(req, res, next) {
    req.data = { value: "middleware"};
.use(function(req, res, next) {


Cover of Node.js Blueprints


modifying req. & res. objects in Middleware