How to get the unparsed query string from a http request in Express

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)

Leave a Comment

tech