Tell us what’s happening:
I think I have basically understood what the general task is here.
I have a couple of general questions:
- This code comes out of nowhere that I got from github into repl.it. Am I right to assume, that this is an intended abstraction to make things easier for me? So I simply do not care at this point? Or did I miss that part because I only did the courses “Responsive Web Design” and “JavaScript Algorithms and Data Structures” so far and skipped “Front End Development Libraries” and “Data Visualization”. I would not have gotten to know that in these courses, right?
- I have trouble debugging and trying things out in the repl.it environment. In the “JavaScript Algorithms and Data Structures” - part of the curriculum you could see the console in real time to react on your code. Now you have to run the server and dig through the shipload of messages that are generated, right?
- In the code below this console complains
“var string = req.method + " " + req.path + " - " + req.ip;
^
ReferenceError: req is not defined”
I was under the impression that req.method, req.path, and req.ip would be variables and methods that were defined elsewhere in the magical black box, I am using here.
I seem to be missing a basic understanding of the whole concept. Is there more for me to read? Can you help me with your answers?
Your code so far
The code in the file “myApp.js”:
var express = require('express');
var app = express();
var string = req.method + " " + req.path + " - " + req.ip;
app.use(function middleware(string) {
// Do something
// Call the next function in line:
next();
});
app.use("/public", express.static(__dirname + "/public"));
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36
.
Challenge: Implement a Root-Level Request Logger Middleware
Link to the challenge: