Tell us what’s happening:
I got “Root level logger middleware should be active” error. What is the problem in my code?
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?
Also, could you share your 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:
Go to the Free Code Camp lesson (where the submit button is)
Open the browser console (F12 in most browsers).
Go to the Network tab and click on the XHR button.
Submit your code again (without closing the browser console).
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}.
lasjorg
September 30, 2022, 4:40pm
8
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.
lasjorg
September 30, 2022, 5:50pm
10
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.
lasjorg
September 30, 2022, 6:11pm
12
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?
lasjorg
September 30, 2022, 6:51pm
14
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
system
Closed
April 2, 2023, 4:49am
17
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.