0

I have a express.js application which is working fine. But it is getting big and sometimes I get confused if a certain route is already defined or not. I need a way to see the routes that my express app is serving.

I want to see it on runtime either in terminal or in the inspector of chrome. I am using --inspect option when I start my app. I don't want to use some node module and write code in my app to see routes all the time in terminal. It should be on demand basis. I remember some feature like this present in Ruby on Rails - I guess it was rake routes or something. Need help on this, it will make my life easy.

I used app._router.stack. The problem with it is that I cannot see the routes defined in the mounted routes.

I have formed subroutes - /admin and /api. These subroutes are again combinations of other subroutes. The hierarchy may get more deeper as the application grows. The app._router.stack isn't going to work and writing 'someRouter.stack' for each subroute and console.log it is not a solution for me.

Vineet 'DEVIN' Dev
  • 1,183
  • 1
  • 10
  • 35
  • Possible duplicate of [How to get all registered routes in Express?](https://stackoverflow.com/questions/14934452/how-to-get-all-registered-routes-in-express) – Kalamarico Sep 24 '17 at 21:15
  • https://stackoverflow.com/a/28086959/4684597 – Zoran Pandovski Sep 24 '17 at 21:16
  • I recommend you even to refactor your code and organize your routes. For example provide RESTfull or semi-RESTfull API to manage your entities. Then devide the routes to multiple files - each will take care of its entity. Then you will always know where to check if you already implemented the method - you will know in which file/files to check (according RESTful notation) – Alexander Sep 24 '17 at 21:41
  • There are modules available that may help you such as https://www.npmjs.com/package/express-list-endpoints – winseybash Sep 25 '17 at 11:05

0 Answers0