Files
Sudipto Ghosh 29823fe495 Expanded guides for some APIs and Microservices challenges and fixed links to the source files (#36131)
* Expanded the solution for the 'Get Route Parameter Input from the Client' challenge

* Expanded the guide for the 'Use body-parser to Parse POST Requests' challenge

* Rewritten guide for the 'Serve JSON on a Specific Route' challenge and fixed source link

* Expanded the guide for the 'Serve Static Assets' challenge

* Expanded solution to the 'Get Query Parameter Input from the Client' challenge and fixed links to source file

* Added solution to the 'Chain Middleware to Create a Time Server' challenge and fixed link to source file

* Rewrite the 'Start a Working Express Server' challenge

* Expanded the guide for 'Expand Your Project with External Packages from npm'

* Added reference to semantic versioning in 'Add a Version to Your package.json'

* fix/remove-links+fix-solutions

* fix/remove-more-links
2019-07-01 20:35:15 -05:00

865 B

title
title
Implement a Root-Level Request Logger Middleware

Implement a Root-Level Request Logger Middleware

It is easier to write this challenge all at the top (there is already a stub for it). This is because middleware must be placed the function calls you want it to be used for.

To set up your own middleware you can do it like so:

app.use(function middleware(req, res, next) {
  // Do something
  // Call the next function in line:
  next();
});

If you have trouble formatting the string correctly, one way to do it looks like:

  var string = req.method + ' ' + req.path + ' - ' + req.ip;

Resources