Skip to content

Instantly share code, notes, and snippets.

@simonista
Created February 16, 2022 15:55
Show Gist options
  • Select an option

  • Save simonista/d2d3f7f57cbc6ed7b63b4fbe1f116b98 to your computer and use it in GitHub Desktop.

Select an option

Save simonista/d2d3f7f57cbc6ed7b63b4fbe1f116b98 to your computer and use it in GitHub Desktop.

Revisions

  1. simonista created this gist Feb 16, 2022.
    14 changes: 14 additions & 0 deletions print-express-routes.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    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', '')
    printRoutePaths(r.handle, `${prefix}${newPrefix}`)
    }
    })
    }