expressjs / expressjs/express

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

Open
#6,481 10 comments 6 reactions 0 assignees View on GitHub
module:router
Dominant language
JavaScript
Stars
69.5k
Forks
25k
Avg merge
4d 20h
Merged PRs (30d)
9

Description

### 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`](https://github.com/expressjs/express-list-endpoints). A native utility would make this more reliable and portable.

#### Example usage

```js
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!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.