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

Not able to pass this level
Is my code missing something or the format is error or misplaced?

See the image attach for my codes for this level. You can refer to this link for my code boilerplate-express (2) - Replit

Your browser information:

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

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

Link to the challenge:

The repl link you posted doesn’t work: " boilerplate-express-2.vlchung.repl.co unexpectedly closed the connection."

Yeah…I know because my code is not working

Can you post a link to your code please? (Rather than your live project link).

I don’t know if my code is misplaced / wrong format / missing something. Can you help me to check?

let express = require(‘express’);
let app = express();
console.log(‘Hello World!’);

app.use(function middleware(req, res, next) {
var str = req.method + " " + req.path + " - " + req.ip;
console.log(str);
next();
});

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

// Normal usage
app.use(express.static(__dirname + “/public”));

// Assets at the /public route
app.use(“/public”, express.static(__dirname + “/public”));

process.env.MESSAGE_STYLE=‘uppercase’;

app.get(‘/json’, function(req, res){
// Variable assignment as object
var response = {
“message”: “Hello json”
};

if(process.env.MESSAGE_STYLE===‘uppercase’){
//Override message attribute value based on condition
response.message = response.message.toUpperCase();
}

return res.json(response);
});

No, I mean a direct link to your repl code.
My link for example:

https://replit.com/@igorgetmeabrain/boilerplate-express#myApp.js

This one?

https://replit.com/@vlchung/boilerplate-express-2#myApp.js

You’ve lost a line of code from the bottom of your myApp.js file:

module.exports = app;

Add that back in and your repl should run properly.

I added back the code that you mentioned and passed this level.

Thanks a lot! :grinning:

1 Like