Logger Middleware Test Fail - NaN

I am unable to pass this test and can’t understand why. I’ve read multiple posts about bugs in the FCC test suite for this course and I wonder whether this challenge is impacted.

Code snippet:

const logger = (req, res, next) => {
  let str = req.method + " " + req.path + " - " + req.ip;
  console.log(str);
  next();
}
app.use(logger)

Example of logs returned in the console:

GET/public/style.cssNaN
*
GET/NaN
*
GET/public/style.cssNaN
https://www.freecodecamp.org
*

Project link

solution: https://replit.com/@drrompecabezas/boilerplate-express

Challenge: Implement a Root-Level Request Logger Middleware

Link to the challenge:

The following solution worked, but I still don’t understand why the first one failed.

app.use((req, res, next) => {
  console.log(req.method + " " + req.path + " - " + req.ip);
  next();
})

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.