I can’t understand why is this not working!
help please
app.use(function(req, res, next){
console.log("req.method+’ ‘+req.path+’-’+req.ip");
next();
})
FCC says “root-level logger is not working as expected”
link to the challenge:
I can’t understand why is this not working!
help please
app.use(function(req, res, next){
console.log("req.method+’ ‘+req.path+’-’+req.ip");
next();
})
FCC says “root-level logger is not working as expected”
link to the challenge:
Just out of curiosity, why did you put your req
in the console.log
using string quotes?
// GET IT EASY THIS WAY
//
app.use(function middleware(req,res,next) {
var string = req.method + ’ ’ + req.path + ’ - ’ + req.ip;
res.send(string);
console.log(string);
next();
});
If you call .send
on a request, you’re terminating the request and whatever you may have chained next is getting thrown into oblivion…
It is res.send i.e.
sending on response
after the request is successfully completed.
It also means that if the request is not successful, then the next function will be executed…
// EVEN IF I USE
res.json
// THE RED PANDA SMILES
var express = require(‘express’);
var app = express();
// --> 7) Mount the Logger middleware here
app.use(function middleware(req, res, next){
var string = req.method + ’ ’ +req.path +’ - ’ + req.ip;
res.json(string);
console.log(string);
next();
});
HINT : Try loading the middleware function before all other methods.