-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Feature Request: Ability to list routes with method + middleware, one entry per HTTP method #6481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
you kind of can already do something similar but... |
I quickly (and not necessarily in an elegant way) adapted the script from the excellent package express-list-endpoints package, and it seems that this version work with Express 5. However, I’m not sure if the regular expressions are fully compatible with the new path-to-regexp@8. The script currently returns a string list of all methods, routes, and their associated middlewares — not yet an array of objects, which would be more structured and convenient to work with. This kind of functionality could be a great built-in feature in Express 5, helping developers map out routes and even build documentation or Swagger-like outputs more easily.
It seems that many developers have tried to achieve the same goal using different approaches (stackoverflow). |
With the help of my AI friend 😉, I completely rewrote the listRoutes function, and overall everything is running really well! The only challenge left is detecting sub-router routes. I've explored many different approaches, but it seems very difficult — if not impossible — to retrieve the sub-route paths passed with statements like app.use("/subpath", router). It looks like these paths simply aren't available in the stack. Any insights, tips, or ideas would be truly appreciated! It's an exciting problem to work on, and it really highlights how valuable it would be for Express 5 to offer a built-in way to list all registered routes, instead of having to dive deep and reverse-engineer the framework. Thanks a lot in advance for any help!
|
I would love for this to become part of the framework as well. In 4.X that I was using I too used the app._router._stack approach but just switching to 5.X those internal variables are gone which makes sense. Having a framework capability would be great. We use this for auditing purposes to see if any routes we have created have never been called. |
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:
Currently, developers have to dig into
app._router.stack
, which is undocumented and subject to change, or use third-party packages likeexpress-list-endpoints
. A native utility would make this more reliable and portable.Example usage
Each route-method combination would be a separate entry for clarity and ease of processing.
Expected behavior
Thanks for the amazing framework — would love to help improve the developer experience!
The text was updated successfully, but these errors were encountered: