Skip to content

Instantly share code, notes, and snippets.

@lukaswhite
Created October 3, 2014 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaswhite/467a91d62b5d66d82341 to your computer and use it in GitHub Desktop.
Save lukaswhite/467a91d62b5d66d82341 to your computer and use it in GitHub Desktop.
Getting a list of routes from an Express 4 application
var _ = require('lodash')
var routes = _.map(_.filter(app._router.stack, function(item){
return (item.route != undefined)
}), function(route){
return {
path: route.route.path,
method: Object.keys(route.route.methods)[0]
}
})
/**
Sample output:
{ route : '/', method: 'get' },
{ route : '/things', method: 'get' },
{ route : '/things', method: 'post' },
{ route : '/things/:id', method: 'get' },
...etc
**/
_.each(routes, function(route){
console.log(route.method.toUpperCase() + '\t' + route.path)
})
/**
Sample output:
GET /
GET /things
POST /things
GET /things/:id
...etc...
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment