How to log all available routes in NodeJS + ExpressJS application?
I have a NodeJS + ExpressJS application, where I have tons of routes getting added in different places. I want to log all the available routes in one place, let's say after the server start. How can I do that in ExpressJS?
1 Answer
5 years ago by Eleven
We can get all available routes in an ExpressJS application from router's stack. Following code shows you how to log all routes.
var express = require('express');
var app = express();
// adding all routes....
// logging routes
app._router.stack.forEach(function (r) {
if (r.route && r.route.path) {
console.log(r.route.path)
}
});
5 years ago by Karthik Divi