Routers — Basics · Express

Split the app into routers, one per resource and one file each, mounted under their paths. Load a cat once for every route with :id, nest an owner's cats under the owner, and see what the request knows about where it is.

What you will learn

Read the theory for Routers

All Basics lessons

All Express courses

loading types…

What you'll learn

  • Group routes in an express.Router() in their own file and mount it with app.use(path, router)
  • Load what a route parameter names once with router.param, and scope middleware to one router
  • Nest a router under a parameterised path with mergeParams, and read req.baseUrl, req.path and req.originalUrl