app.route()

Returns a single Route instance so you can chain verb handlers for one path.

Since Express 4 Spec ↗

Syntax

app.route(path)

Parameters

NameTypeRequiredDescription
path string Yes The route path to create a chainable Route for.

Returns

Route — A Route on which to chain .get(), .post(), etc.

Examples

app.route('/books')
  .get((req, res) => res.json(listBooks()))
  .post((req, res) => res.status(201).json(addBook(req.body)));
Output
$ curl localhost:3000/books
[...]
app.route('/books/:id')
  .get((req, res) => res.json(getBook(req.params.id)))
  .delete((req, res) => res.sendStatus(204));
Output
$ curl -X DELETE localhost:3000/books/1
(204 No Content)

Notes

Avoids repeating the path string and duplicate route definitions. Functionally similar to a Router but scoped to one path. Combine with `express.Router()` for larger groupings.

See also