Don't encode urls in querystring stringify

Is there any option for qs.stringify that will not encode the urls?

$ node
> var qs = require("querystring");
> qs.stringify({"url": ""});

I want the folowing output:


Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

It’s a little late, but for the next person, you can do:

Solution 2

Late answer again, but…
qs.stringify() has option encode:false which actually disable the URI encoding.

Qs.stringify documentation

You can also use it in nodejs request/request module as:

  url: 'http://url.domain'
  qs: {
    qs1: 'thisIsNotEncodedInTheRequest%20://асд'
  qsStringifyOptions: {
    // encoding: false /** (OLD VERSION - I think is deprecated yet) */
    encode: false

Solution 3

Not directly, no. Although, if you are not escaping the value in the query string then there is hardly any benefit to using querystring at all. Mind as well just do: var q = 'url='

EDIT: From looking at the source, the only way would be to change the behavior of (i.e. overwrite) the querystring escape() function – which is possible but not a good idea.

Solution 4

Here is the answer:

qs.stringify({url: ""}, { encodeURIComponent: uri => uri });

The option “encodeURIComponent: uri => uri” is to disable the encoding.

Solution 5

This worked for me

qs.stringify({url: ""}, null, null, { encodeURIComponent: qs.unescape });

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply