Help with backend path - create logger

Tell us what’s happening:
Please have a look what is wrong with my code;

var express = require('express');
var app = express();
var port = 8000;
app.use(function middleware(req,res,next) {
  var string = req.method + " " + req.path + " - " + req.ip;
  res.send(string);
  console.log(string);
  next();
}) 

app.listen(port)
 module.exports = app;

Your project link(s)

solution: https://replit.com/@ayaderaghul/boilerplate-express-2

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36

Challenge: Implement a Root-Level Request Logger Middleware

Link to the challenge:

Remove the res.send before the log. You are only supposed to log it out.

Agree with lasjorg… remove the res.send from the app.use. You don’t need to send a response object. Should work normally. Make sure to run your project so that the test can pass when you provide your url. You should be able to see your logger function working in the console.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.