Getting req.params in order in Express JS
- by Adam Terlson
In Express, is there a way to get the arguments passed from the matching route in the order they are defined in the route?
I want to be able to apply all the params from the route to another function. The catch is that those parameters are not known up front, so I cannot refer to each parameter by name explicitly.
app.get(':first/:second/:third', function (req) {
output.apply(this, req.mysteryOrderedArrayOfParams); // Does this exist?
});
function output() {
for(var i = 0; i < arguments.length; i++) {
console.log(arguments[i]);
}
}
Call on GET: "/foo/bar/baz"
Desired Output (in this order):
foo
bar
baz