January 2018
Beginner
658 pages
13h 10m
English
In order to explore middleware, we'll create some basic middleware. Just following where we call app.use registering our Express static middleware, we'll call app.use again:
app.use(express.static(__dirname + '/public'));app.use();
Now app.use is how you register middleware, and it takes a function. So, we'll pass in an arrow function (=>):
app.use(() => {});
The use function takes just one function. There is no need to add any other arguments. This function will get called with the request (req) object, the response (res) object and a third argument, next:
app.use((req, res, next) => {});
Now request and response objects, these should seem familiar by now. They're the exact same arguments we get whenever we register ...