I know that Express checks for query string (e.g. ?a=1&b=2) and parses it if present by default. And that req.query is the object which contains the key/value pairs. Is there a way of disabling this behavior and ignore the qs completely?
I need this because I parse the query string client side, and since I receive a huge amount of requests and the qs are pretty long I don't want to waste server resources each time parsing the query string (which means that Express would need to decode URI components in the string, split the string, do a for loop for each key value pair, do another split for each pair, create a new object etc. which is very expensive). Is this possible?
You can configure the query parser (have a look to the doc):
app.disable('query parser')
Place it after the express initialization and before the router.
You could also pass an empty function to the query parser just in case you need some kind of fine tuning in the future:
app.set('query parser', function(qs, options) {
// qs is a query string, process it here
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With