Stuck on Implement a Root-Level Request Logger Middleware

I’ve been stuck on this one for a bit now, I’ve gone over previous forum posts and tried all suggestions. Still, the test “Root level logger middleware should be active” fails. As far as I can see, the console outputs what it’s supposed to. I have tried resetting the project, commenting out code from earlier challenges, and rewriting the code to match code from supposedly working forum solutions.

My code:

var express = require('express');
var app = express();

app.use(function middleware(req, res, next) {
  console.log(`${req.method} ${req.path} - ${req.ip}`)
  next();
});

console.log("Hello World");

app.get("/", function(req, res) {
  res.sendFile(__dirname + "/views/index.html");
})

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

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

My repl.it:
https://repl.it/@oddgrd/boilerplate-express-5#myApp.js
Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0.

Challenge: Implement a Root-Level Request Logger Middleware

Link to the challenge:

1 Like

I’m having the same issue. I’m wondering if it has something to do with this: Use the .env File - Issue

I suspect so too, but I made a post about the .env challenge as I didn’t know about the bug. I asked if there were any issues with this challenge, but was told no, no known bugs on this challenge, only the .env challenge.
I will just skip both of these I think, and hope the rest of the challenges work out.

I skipped to the next challenge, where the test also fails. I tried the solutions posted in Get Hint, the tests still fail. I am at a loss about this section, it feels like I’ve wasted hours on something that just doesn’t work. I may have done something incorrectly, but I don’t see how, as I have tried several supposed solutions, all similar to mine.

I’m seeing the same as you, the following I’m currently failing:

  • Use the .env File
  • Implement a Root-Level Request Logger Middleware
  • Chain Middleware to Create a Time Server

Other than this, all other challenges in this module are passing.

I am at a loss about this section, it feels like I’ve wasted hours on something that just doesn’t work.

Its ok, in my limited experience, this happens from time to time and it’s kind of par for the course. Even with this happening I’m sure you’re still making good progress.

Same here! These three exercises won’t pass the tests…
There was no problem with the next one “Get Route Parameter Input from the Client”.

Yes, I too pass all except these three. I’m quite sure I’ve done them correctly and understood it though, so no biggie. Will move on and do them when they are fixed. Thank you for your positivity and feedback!

me too, so far this test and the previous have failed despite me checking and rechecking my solutions. On the plus side searching for the errors often teaches us more than things going right first time

To pass the test you have to run npm update --save
More details here: Use the .env File - Issue [RESOLVED]

1 Like

This fixed it. Thanks!