javascript - Creating Express param middleware that updates the request object -


im trying update req.conversation before handled function called read. know middleware being called before read when log req.conversation object in read doesnt reflect updates made in middleware.

/** * conversation middleware */ exports.conversationbyid = function(req, res, next, id) {      if (!mongoose.types.objectid.isvalid(id)) {         return res.status(400).send({             message: 'conversation invalid'         });     }      conversation.findbyid(id).populate('user', 'displayname').populate('readers', 'displayname').exec(function(err, conversation) {         if (err) return next(err);         if (!conversation) {             return res.status(404).send({                 message: 'conversation not available'             });         }         req.conversation = conversation;         next();     }); }; 

where id parameter in middleware callback coming from? if it's url param (e.g. /conversations/:id) should req.params.id.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -