Created
October 22, 2019 14:53
-
-
Save imixtron/892e61c86fa631d01b8df1ba19baeb61 to your computer and use it in GitHub Desktop.
Get all registered routes from express router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// small function to get routes from an express router | |
// https://stackoverflow.com/questions/14934452/how-to-get-all-registered-routes-in-express#answer-26275395 | |
export function listRoutes(...args: Router[]){ | |
for (var i = 0; i < arguments.length; i++) { | |
if(arguments[i].stack instanceof Array){ | |
console.log(''); | |
arguments[i].stack.forEach(function(a: any){ | |
var route = a.route; | |
if(route){ | |
route.stack.forEach(function(r: any){ | |
var method = r.method.toUpperCase(); | |
console.log(method,'\t',route.path); | |
}) | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment