0

I'd like to use a app.use:

app.use(function(req, res, next){
    console.log('%s %s', req.method, req.url);
    next();
});

But it only works if I have no app.get or app.post in my code, if I have one my app.use is ignore.

I'd like to execute a script each time a app.get or a app.use is called

I also try:

app.use(function(req, res, next){
    console.log('%s %s', req.method, req.url);
    app.get('/',function(req,res){console.log('aa')})
    next();
});

in this case my app.get is ignore

Thanks for your help

Ajouve
  • 9,735
  • 26
  • 90
  • 137

1 Answers1

1

you have to put your app.use() above the router. The router is usually inside the express configuration so just put your app.use() above the configuration. Something like this:

app.use(function(req, res, next) {
  console.log('awesome');
  next();
})

app.configure(function(){
  // config
  app.use(app.router);
});

Also have a look at the build in logger.

zemirco
  • 16,171
  • 8
  • 62
  • 96