You can then use a router for a particular root URL in this way separating your routes into files or even mini-apps.
A router behaves like middleware itself
ery Express application has a built-in app router.
A router object is an isolated instance of middleware and routes. You can think of it as a “mini-application,” capable only of performing middleware and routing functions.
body object containing the parsed data is populated on the request object after the middleware
utomatic inflation of gzip and deflate encodings.
only looks at requests where the Content-Type header matches the type option.
body-parser extracts the entire body portion of an incoming request stream and exposes it on req.body. The middleware was a part of Express.js earlier but now you have to install it separately.
error-handling functions have four arguments instead of three: (err, req, res, next).
that the default error handler can get triggered if you call next() with an error in your code more than once, even if custom error handling middleware is in place.
after you have started writing the response (for example, if you encounter an error while streaming the response to the client) the Express default error handler closes the connection and fails the request.
The res.statusCode is set from err.status (or err.statusCode). If this value is outside the 4xx or 5xx range, it will be set to 500.
If you pass an error to next() and you do not handle it in a custom error handler, it will be handled by the built-in error handler;
Express comes with a built-in error handler that takes care of any errors that might be encountered in the app. This default error-handling middleware function is added at the end of the middleware function stack.
灾区官员提出:不要救济粮、不要救济款、不要救济物
If this fails then the synchronous error handler will catch it. If you had done this processing inside the readFile callback then the application might exit and the Express error handlers would not run.
by reducing the asynchronous code to something trivial. For example:
anything to the next() function (except the string 'route'), Express regards the current request as being an error and will skip any remaining non-error handling routing and middleware functions.
If no rejected value is provided, next will be called with a default Error object provided by the Express router.
middleware that return a Promise will call next(value) automatically when they reject or throw an error