Skip to content

Instantly share code, notes, and snippets.

@stefanocudini
Created October 14, 2021 09:13
Show Gist options
  • Save stefanocudini/a30445a21927a37ee18cf209be8beba8 to your computer and use it in GitHub Desktop.
Save stefanocudini/a30445a21927a37ee18cf209be8beba8 to your computer and use it in GitHub Desktop.
expressjs list of defined entrypoint in app
function availableRoutes() {
return app._router.stack
.filter(r => r.route)
.map(r => {
return {
method: Object.keys(r.route.methods)[0],
path: r.route.path
};
});
}
@stefanocudini
Copy link
Author

stefanocudini commented Oct 14, 2021

short version:

console.log( app._router.stack.filter(r => r.route).map(r => ({[Object.keys(r.route.methods)[0]]: r.route.path })) )```

@stefanocudini
Copy link
Author

stefanocudini commented Oct 14, 2021

very short version:

console.log( app._router.stack.filter(r => r.route).map(r => `${Object.keys(r.route.methods)[0]} ${r.route.path}`) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment