Middleware and Routers
Middleware and Routers: Middleware: Code That Runs on Every Request, Organizing Routes with express.Router.
Updated
- Middleware: Code That Runs on Every Request (Journeyman): Middleware is a function with (req, res, next) that Express runs on a request before the routes, in the order you add it, so a log line, a timer or a body reader is written once instead of in every route.
- Organizing Routes with express.Router (Journeyman): An express.Router holds one resource's routes in a file of its own, app.use("/games", gamesRouter) puts them under their path, and app.js exports the app while server.js starts it, so tests can use the app without a port.