querystring module
The querystring module provides APIs to parse and format URL query strings.
To access APIs in the querystring module, use the
require('querystring') statement.
querystring.escape()
Performs URL percent-encoding on the given URL query string in a manner that is optimized for the specific requirements of URL query strings.
Syntax
querystring.escape(str)
| str | The URL query string to escape. |
The querystring.escape() API is normally used by the
querystring.stringify() API so that it can be overridden if necessary.
querystring.parse()
Deserializes a query string to an object.
Syntax
querystring.parse(str[, sep[, eq[, options]]])
| str | The URL query string to parse. |
| sep | Optional: The override to the default separator (&) character. |
| eq | Optional: The override to the default assignment (=) character. |
| options | The
Options object can contain the maxKeys property, which is 1000
by default. If so, it is used to limit processed keys. Set maxKeys to 0 to remove
the key count limitation. |
var querystring = require ('querystring');
querystring.parse('foo=bar&baz=qux&baz=quux&corge');
// returns {foo: 'bar' , baz: ['qux' , 'quux' ], corge: ''}
querystring.stringify()
Serializes an object to a query string.
Syntax
querystring.stringify(obj[, sep[, eq[, options]]])
| obj | The object to serialize to a query string. |
| sep | Optional: The override to the default separator (&) character. |
| eq | Optional: The override to the default assignment (=) character. |
| options | Optional: The function to use when converting URL-unsafe characters to percent-encoding in the query string. The default value is querystring.escape(). |
var querystring = require ('querystring');
querystring.stringify({ foo:'bar', baz:['qux','quux'], corge:''});
// returns 'foo=bar&baz=qux&baz=quux&corge='
querystring.stringify({ foo:'bar', baz:'qux'},';',':');
// returns 'foo:bar;baz:qux'
querystring.unescape()
Performs decoding of URL percent-encoded characters on the given URL query string.
Syntax
querystring.unescape(str)
| str | The URL query string that includes the URL percent-encoded characters. |
The querystring.unescape() API is normally used by
querystring.parse() so that it can be overridden if necessary.