3 ms·
The other thing you can't properly get using a map is precedence. By building an array you can go through it in order so that middleware is run in the order it
by andrewstuart2 12y ago
The other thing you can't properly get using a map is precedence. By building an array you can go through it in order so that middleware is run in the order it was defined in the code.
That way, if you have any route definitions that match early on, especially if they allow execution to continue ( by calling next() ), they will run before any following code does.
This allows your code to be very expressive and intuitive when reading it, as things have a defined order.
I imagine the recursion is also done so that you can use a route object anywhere in that ordered stack and it will apply all its own handlers, in the order they were defined in the code.