To get all routes registered in express.js, this snippet gets the work done:
const routes = [];
app._router.stack.forEach((middleware) => {
if (middleware.route) {
routes.push(
`${Object.keys(middleware.route.methods)} -> ${middleware.route.path}`
);
}
});
console.log(JSON.stringify(routes, null, 2));
Possible result:
[
"post -> /customers"
"put -> /customers/:id",
"delete -> /customers/:id"
]