Implement a Root-Level Request Logger Middleware

I didn’t find any correct answer for the error I got in my Implement a Root-Level Request Logger Middleware so here is the solution.

const logger = (req, res, next) => {
  console.log(`${req.method} ${req.path} - ${req.ip}`);
  next();
};

app.get("/", logger, (req, res) => {
  res.sendFile('/views/index.html');
});
app.get("/json", logger, (req, res) => {
  if (process.env.MESSAGE_STYLE === "uppercase")
    res.json({
      message: "Hello json".toUpperCase()
    });
  else
    res.json({
      message: "Hello json"
    });
});

Welcome there,

If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge.
This button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Also, please add information to your post body. Currently, we do not know what you are struggling with.

Thank you.