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

Tell us what’s happening:

I got “Root level logger middleware should be active” error. What is the problem in my code?
Ekran Alıntısı

Your browser information:

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

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

Link to the challenge:

Hello!

Does is show anything on the console?

image

Also, could you share your entire code?

Console:
Ekran Alıntısı
Entire Code:

Your code is correct, so I’m not sure why is it failing… Skip it for now.


On the other hand, you can try this:

  1. Go to the Free Code Camp lesson (where the submit button is)
  2. Open the browser console (F12 in most browsers).
  3. Go to the Network tab and click on the XHR button.

  1. Submit your code again (without closing the browser console).
  2. Click the request that has your project URL on it

You should see something like this:

Does the request succeeds with a code 200? Does it respond with a passed: true value?

The request was successful with code 200. But I get {“passed”:false}.


Ekran Alıntısı4

Can you put your code up on GitHub or replit, so we can test your code?

1 Like

Github repo link:

Your code is passing for me.

What do you get if you go to the URL in the browser?

http://localhost:3000/_api/root-middleware-logger

Do you then see the correct object and the logs in the node console?

When I go to this link, I see {“passed”:false} and also my console looks like this.

Odd, so is the middleware not running at all?

app.use((req, res, next) => {
  console.log('Middleware did run');
  next();
});

app.use((request, response, next) => {
  console.log('Request middleware did run');
  console.log(request.method + ' ' + request.path + ' - ' + request.ip);
  next();
});

Restart the server and see if you get any logs.

If you do not see any logs I would delete the node_modules folder and do npm i again. Restart the server and see if that does anything.

My console seems okey and I also tried deleting and reinstalling the node_modules package. I’m still getting an error.

Try deleting the node_modules and package-lock.json file, then install again.

I feel like it might be an issue with the test dependency as I don’t see why it would give you the fail object when testing it locally using the URL I posted. Other than that, I don’t really know why it would fail.

When did you clone the repo, was it recently?

Unfortunately I didn’t get any results. I’m working in my local and I paste “http://localhost:3000/” in the “solution link” part. Could I have a problem because of this?

No, it should work just fine locally, it does for me with your code. Maybe you have something blocking the request somehow, not sure (security software). Does using a different browser do anything?

I guess you can try using Replit instead.

1 Like

I had no problems with the replit. Thank you for your help!

1 Like