I have a web application built using Node.js and Express. Now I would like to list all registered routes with their appropriate methods.
E.g., if I have executed
app.get('/', function (...) { ... });
app.get('/foo/:id', function (...) { ... });
app.post('/foo/:id', function (...) { ... });
I would like to retrieve an object (or something equivalent to that) such as:
{
get: [ '/', '/foo/:id' ],
post: [ '/foo/:id' ]
}
Is this possible, and if so, how?
express 3.x
Okay, found it myself … it’s just
app.routes🙂express 4.x
Applications – built with
express()Routers – built with
express.Router()Note: The stack includes the middleware functions too, it should be filtered to get the “routes” only.