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

Error : Root level logger middleware should be active
I’m on the exercice BackEnd : Implement a Root-Level Request Logger Middleware
I have tried update in similar posts and everything else
can someone please help

let express = require('express');
require('dotenv').config()
let app = express();
let absolutePath = __dirname + "/views/index.html";
let middlewarePath = __dirname + "/public";

app.use((req, res, next)=>{
  let string = `${req.method} ${req.path} - ${req.ip}`;
  console.log(string)
  next()
})

app.use("/public", express.static(__dirname + "/public"));



app.get("/",function(req, res) {
        res.sendFile(absolutePath)
  })

app.get("/json", (req, res)=>{
    if (process.env.MESSAGE_STYLE === "uppercase") {
        res.json({"message": "HELLO JSON"})
      } else {
        res.json({"message": "Hello json"})
      }
})
module.exports = app;

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

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

Link to the challenge:

Your code looks ok but can you give a direct link to your project code please? There may be a problem elsewhere.

I don’t think this is the correct syntax that the challenge is looking for, check this again to be sure.

That syntax is fine if it includes the backticks, which it does in the OP’s code. It’s a matter of preference, and I would choose to do a simple string concatenation instead but template literal is perfectly valid.

I was just referring to the spacing, the challenge seemed specific about a space between each element.

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