K
K
Kroid2014-05-31 14:11:20
JavaScript
Kroid, 2014-05-31 14:11:20

[express] Get all routes in readable format

There was an idea to generate documentation on request to the server.
Express 4 renders all routes in this way:
app._router.stack
It turns out rather unreadable. Is there a way to get the routes as the same character strings as I set them?
GET '/user:id'
POST '/post/new'
something like that.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Krasnodemsky, 2014-06-09
@Prognosticator

Try this
View
Get

for(var i = 0; i < router.stack.length; i++) {
    console.log(router.stack[i].route.path);
    // здесь ваша обработка роутов
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question