Application-level middleware is bound to the app object with app.use().
Router-level middleware works the same way, but is bound to an express.Router() instance with router.use().
Error-handling middleware takes four arguments, (err, req, res, next).
Built-in middleware ships with Express, such as express.static and express.json.
Third-party middleware comes from npm packages, such as morgan, cors and helmet.
The types overlap. Third-party cors() mounted with router.use() is also router-level middleware, and an error handler can sit on the app or on a router.
Rewriting in plainer words…
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.