Implement a Root-Level Request Logger Middleware

Implement a Root-Level Request Logger Middleware
0.0 0

#1
app.all((req,response,next)=>{
  var method=req.method;
  var path=req.path;
  var ip=req.ip;
  console.log(method+' '+path+' - '+ip);
  next();
})

what else should I use to complete this challenge


#2

Same problem here, don’t know what is the passing criteria of this challenge…

// running test
root-level logger is not working as expected
// tests completed

#3

What does the rest of your code look like? Express uses middleware in order, so that could be an issue.


#4

Pay attention to this:

Hint: Express evaluates functions in the order they appear in the code. This is true for middleware too. If you want it to work for all the routes, it should be mounted before them. that is, place your code before the routes!


#5

Hi, i used app.use instead of app.all and that worked


#6

put this line

app.use(function(req, res, next){console.log(req.method + ' ' + req.path + ' - ' + req.ip); next();})

Just after you define var app = express()