1

I'm sure I can exec a script or a function each time I exec a request (app.get or app.post) with the res and req var but I cant' find how

can you please help me

Thanks

Edit:

I try

var express = require('express')
, http = require('http')
, path = require('path');

var app = express();

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

in my app.js but I never have aa in my console

my app.get are in controllers:

files = fs.readdirSync(__dirname + '/controllers');
files.forEach(function(file){
    var name = file.replace('.js', '');
    require('./controllers/' + name)(app, models);
});

if I remove this code app.add works but I can't use app.get

1
  • Try removing the argument err from your middleware function. Commented Nov 18, 2012 at 22:10

1 Answer 1

3

You need to use general middleware:

app.use(function (req, res, next) {
  //do stuff
  next();
});
Sign up to request clarification or add additional context in comments.

2 Comments

I edit my post, I think app.use have to be set somewhere particular
Cause you have 4 arguments to your middleware which means it's error middleware.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.