December 2018
Intermediate to advanced
642 pages
15h 5m
English
Let's start with our logger. We want it to apply to every path so that we can just omit the path. An alternative would be writing app.use("*", ...), which means exactly the same; we'll also use it as an example. Your logic could do anything, and since we want to log requests, we can just list the current timestamp, the request method, and the requested path. Afterwards—and this is the most important thing—since we haven't finished dealing with the request, calling next() is mandatory, or the request will end up in a processing limbo, never sending anything to the client:
app.use((req, res, next) => { console.log("Logger... ", new Date(), req.method, req.path); next();});
Since we want to have some errors, let's define that ...
Read now
Unlock full access