I can use the below to get the query string.
var query_string = request.query;
What I need is the raw unparsed query string. How do I get that? For the below url the query string is { tt: 'gg' }
, I need tt=gg&hh=jj
etc....
http://127.0.0.1:8065?tt=gg Server running at http://127.0.0.1:8065 { tt: 'gg' }
querystring.parse() Method parse() method is used to parse the URL query string into an object that contains the key value pair. The object which we get is not a JavaScript object, so we cannot use Object methods like obj.
A query string is the portion of a URL where data is passed to a web application and/or back-end database. The reason we need query strings is that the HTTP protocol is stateless by design. For a website to be anything more than a brochure, you need to maintain state (store data).
You can use node
's URL module as per this example:
require('url').parse(request.url).query
e.g.
node> require('url').parse('?tt=gg').query 'tt=gg'
Or just go straight to the url and substr
after the ?
var i = request.url.indexOf('?'); var query = request.url.substr(i+1);
(which is what require('url').parse()
does under the hood)
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