Skip to content

Feature Request: Ability to list routes with method + middleware, one entry per HTTP method #6481

Open
@infuzz

Description

@infuzz

Feature Request: Ability to list routes with method + middleware, one entry per HTTP method

Use case & goal

In medium to large applications, it's often difficult to inspect the full list of declared routes, especially when dealing with multiple routers, dynamic parameters, and complex middleware stacks.

This feature would help developers:

  • Debug route registration and conflicts.
  • Generate API documentation.
  • Inspect which middleware are applied to each route.

Currently, developers have to dig into app._router.stack, which is undocumented and subject to change, or use third-party packages like express-list-endpoints. A native utility would make this more reliable and portable.

Example usage

const routes = app.getRoutes();

console.log(routes);
/*
[
  {
    method: 'GET',
    path: '/users',
    middlewares: ['authMiddleware']
  },
  {
    method: 'POST',
    path: '/users',
    middlewares: ['authMiddleware', 'validateUser']
  },
  {
    method: 'GET',
    path: '/posts/:id',
    middlewares: ['anonymous']
  }
]
*/

Each route-method combination would be a separate entry for clarity and ease of processing.

Expected behavior

  • List all declared routes in the application, including those inside routers (express.Router()).
  • Return one object per method/path combination.
  • Include the route method, full path, and the list of middleware names.
  • Should rely on public APIs if possible (or expose one).
  • Could be provided as app.getRoutes() or express.listRoutes(app).

Thanks for the amazing framework — would love to help improve the developer experience!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions