conditionally use a middleware depending on request parameter express

There is nothing magical about connect/express ‘middleware’: they are just functions – and you can call them as you would call any other function.

So in your example:

app.use(function(req, res, next){
  if (req.query.something) {
    middlewareA(req, res, next);
  } else {
    middlewareB(req, res, next);
  }
});

That said, there might be more elegant ways of constructing hierarchical express applications. Check out TJ’s video

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)