Saturday, 14 September 2013

Modify Node.js req object parameters

Modify Node.js req object parameters

So as usual, I tried to find this question on SO but still no luck.
I am aware that the answer is "Yes, you CAN modify the req object" but
nothing is said about the req object parameters.
For example the following code will throw an error:
app.get('/search', function(req, res) {
req.param('q') = "something";
});
Error:
ReferenceError: Invalid left-hand side in assignment

I imagine this has something to do with the property not having a 'SET'
method or something along those lines.
There are a few scenarios where this could come in handy.

A service that turns quick-links into full blown requests and proxies
those out.
Simply modifying the parameters before sending it off to another function
that you have no desire to modify.
Onto the question, Is there a way to modify the req object parameters?

No comments:

Post a Comment