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

Here it is: express-freecodecamp.

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>”.

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.

Just:
{"passed":false}

Nothing except the 404 for the favicon.

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:

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.

Same issue here. It is passing on 127.0.0.1 where it logs ::ffff:127.0.0.1, but I can’t submit the link as it isn’t secure. Failing on localhost:3000 where it logs ::1 for the IP. Guess I’ll try Replit.

Adding this to server.js should fix it so it can be passed locally.

const dns = require('dns');
dns.setDefaultResultOrder('ipv4first');

It is an issue with later versions of Node.js (17+). I opened an issue for it some time ago but I haven’t had any response to it.

3 Likes

This worked. Had been following along with identical issues as vietan00892b running locally. Can confirm Node.js v18.14.2. Thank you, this is much appreciated.