router.route()

Returns a chainable Route for a path within a router.

Since Express 4 Spec ↗

Syntax

router.route(path)

Parameters

NameTypeRequiredDescription
path string Yes The route path relative to the router.

Returns

Route — A Route to chain verb handlers on.

Examples

const router = express.Router();

router.route('/books/:id')
  .get((req, res) => res.json(getBook(req.params.id)))
  .put((req, res) => res.json(updateBook(req.params.id, req.body)))
  .delete((req, res) => res.sendStatus(204));

app.use('/api', router);
Output
$ curl localhost:3000/api/books/1
{"id":"1"}
router.route('/health')
  .all((req, res) => res.json({ status: 'up' }));
Output
{"status":"up"}

Notes

Keeps all verb handlers for one path together and avoids repeating the path string. Combine with `express.Router()` to organize CRUD resources cleanly.

See also