The code below demonstrates trying to log req.hash_id from middleware. It’s showing up for me as undefined. Is there anyway that I can get this to work? Or easily parse “:hash” out in regular .use middleware?
app.param("hash",function(req, res, next, id){
req.hash_id = id;
return next();
});
app.use(function(req, res, next){
console.log(req.hash_id);
return next();
});
I don’t think you can use
req.paramsinside a middleware function as it is bound to specific routes. You could usereq.querythough, but then you have to write your routes differently, e.g./user?hash=12345abc. Not sure about passing the value fromapp.paramtoapp.use.If you have a specific structure for your routes, like
/user/:hashyou could simply write