Skip to content

Instantly share code, notes, and snippets.

View simonista's full-sized avatar

Simon Williams simonista

  • Lumio
  • Austin, TX
View GitHub Profile
@simonista
simonista / print-express-routes.js
Created February 16, 2022 15:55
Print all the routes defined in an express app (excluding middleware)
function printRoutePaths(router, prefix) {
router.stack.forEach(function(r){
if (r.route?.path){
for (let key in r.route.methods) {
if (r.route.methods[key]) {
console.log(`${key.toUpperCase()} ${prefix}${r.route.path}`)
}
}
} else if (r.name === 'router') {
let newPrefix = r.regexp.toString().replace('/^\\', '').replace('\\/?(?=\\/|$)/i', '')