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

Tell us what’s happening:
I always get this error when running the tests:

// running tests
Root level logger middleware should be active
// tests completed

I’ve tried removing the .env-related stuffs from the last challenge, I’ve tried npm update from similar posts in the forum, I’ve changed my string format to look like the hint. I have no idea why the tests won’t pass.

Here’s my code:

let express = require("express");
let app = express();
const path = require("path");
const indexPath = path.resolve("./views/index.html");

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("/", (req, res) => {
	res.sendFile(indexPath);
});
app.get("/json", (req, res) => {
	res.json({message: "hello json"});
});

module.exports = app;

.
.
.

Your browser information:

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

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

Link to the challenge:

1 Like

Can you provide a link to your project code?

Here it is: express-freecodecamp.

What url are you submitting for this challenge? Also, do you see any errors in either the Node console or the browser console when you try and submit?

I ask as I cloned your repo and passed the challenge locally and imported your repo into repl.it and passed the challenge also.

I submit http://localhost:3000/ like I always do for the previous challenges.
No errors in the Node console either:
image
The browser console just say this, which I think is irrelevant anyway:

This page is in Quirks Mode. Page layout may be impacted. For Standards Mode use “<!DOCTYPE html>”.

What is Quirks mode? Is that some kind of browser extension?

I’m not sure but here’s some info about it. By the way I should clarify, that warning pop up on the freecodecamp page, not on localhost:3000 page, that’s why I thought it’s not relevant anyway.

What do you see in your browser when you go to the following url? http://localhost:3000/_api/root-middleware-logger

Just:
{"passed":false}

OK. Interesting. Open up developer tools and go to the Networking tab. Clear it out and then submit http://localhost:3000. Do you see any strange errors showing there?

Nothing except the 404 for the favicon.

Can you confirm that your current myApp.js is identical to what is showing up on GitHub (that I cloned)? I am starting to wonder if what you have locally and what shows on GitHub (that works) is different.

Show me what you see in the terminal, when you run:

git diff origin/main

Also, make sure to stop/restart the app each time you make changes.

Nothing shows up when I run git diff origin/main, I guess that means there’s no difference? At this point I think I should just move on to the next challenge :sweat_smile:

@lasjorg Any suggestion here?

Have you tried it using Replit?


Does using http://127.0.0.1:3000 give you a checkmark? It won’t actually pass but it can still give you a checkmark. I guess you can also try changing the port in server.js to test it.

You might also try using a VPN just to see if it changes anything. I’d maybe also try with Chrome in a private window with no extensions just to make sure it isn’t an extensions issue.


Your code is passing for me and I haven’t seen anything in the code or screenshots that seems off. The only thing I noticed is that the loopback is logged as ::1 which is IPv6. I don’t see that with my system for the /json route (I do see it for favicon for whatever reason).

I think the only way to really troubleshoot this would be to manually add the fcc-express-bground-pkg package code and do some logging.