Basic Node and Express - Implement a Root-Level Request Logger Middleware

The test still says: “Failed:Root level logger middleware should be active”

my Code:
app.use(“/”,function(req, res, next) {
console.log(${req.method} ${req.path} - ${req.ip});
next();

Console:
OPTIONS * - ::ffff:172.31.128.1
*
GET / - 64.71.144.196
*
GET / - 64.71.144.196
*
GET / - 78.48.127.110
*
GET /public/style.css - 78.48.127.110


Where is the mistake?

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Challenge: Basic Node and Express - Implement a Root-Level Request Logger Middleware

Link to the challenge:

You have problematic syntax in your console.log. If you want to interpolate variables into a string you may use ${variable} syntax with template literal (using backticks), but otherwise, you can simply concatenate:

let yourName = "Bob";
let myName = "Alice";
let exampleVariable = "Hello " + yourName + "my name is " + myName + "!";

Your req values can be concatenated in exactly the same way. Or you can simply add backticks to your original console.log if you prefer.

  • console.log(${req.method} ${req.path} - ${req.ip}); - doesn’t work
  • console.log(req.method + " " + req.path + " - " + req.ip); - does work

Yes, but the first should work if you format correctly with template literal (i.e. include backticks):

console.log(`${req.method} ${req.path} - ${req.ip}`)

Note that backticks are not quote marks.

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