Query string | Node.js v26.8.2 Documentation
https://nodejs.org/api/querystring.html • 35 KB fetched
Open original page
Query string | Node.js v26.8.2 Documentation Skip to content
Node.js
* About this documentation
* Usage and example
* Assertion testing
* Asynchronous context tracking
* Async hooks
* Buffer
* C++ addons
* C/C++ addons with Node-API
* C++ embedder API
* Child processes
* Cluster
* Command-line options
* Console
* Crypto
* Debugger
* Deprecated APIs
* Diagnostics Channel
* DNS
* Domain
* Environment Variables
* Errors
* Events
* File system
* FFI
* Globals
* HTTP
* HTTP/2
* HTTPS
* Inspector
* Internationalization
* Iterable Streams API
* Modules: CommonJS modules
* Modules: ECMAScript modules
* Modules: node:module API
* Modules: Packages
* Modules: TypeScript
* Net
* OS
* Path
* Performance hooks
* Permissions
* Process
* Punycode
* Query strings
* Readline
* REPL
* Report
* Single executable applications
* SQLite
* Stream
* String decoder
* Test runner
* Timers
* TLS/SSL
* Trace events
* TTY
* UDP/datagram
* URL
* Utilities
* V8
* Virtual File System
* VM
* WASI
* Web Crypto API
* Web Streams API
* Worker threads
* Zlib
*
Code repository and issue tracker
Node.js v26.8.2 documentation
* Node.js v26.8.2
* Table of contents
* Query string
* querystring.decode()
* querystring.encode()
* querystring.escape(str)
* querystring.parse(str[, sep[, eq[, options]]])
* querystring.stringify(obj[, sep[, eq[, options]]])
* querystring.unescape(str)
* Index
* Index
* About this documentation
* Usage and example
* Assertion testing
* Asynchronous context tracking
* Async hooks
* Buffer
* C++ addons
* C/C++ addons with Node-API
* C++ embedder API
* Child processes
* Cluster
* Command-line options
* Console
* Crypto
* Debugger
* Deprecated APIs
* Diagnostics Channel
* DNS
* Domain
* Environment Variables
* Errors
* Events
* File system
* FFI
* Globals
* HTTP
* HTTP/2
* HTTPS
* Inspector
* Internationalization
* Iterable Streams API
* Modules: CommonJS modules
* Modules: ECMAScript modules
* Modules: node:module API
* Modules: Packages
* Modules: TypeScript
* Net
* OS
* Path
* Performance hooks
* Permissions
* Process
* Punycode
* Query strings
* Readline
* REPL
* Report
* Single executable applications
* SQLite
* Stream
* String decoder
* Test runner
* Timers
* TLS/SSL
* Trace events
* TTY
* UDP/datagram
* URL
* Utilities
* V8
* Virtual File System
* VM
* WASI
* Web Crypto API
* Web Streams API
* Worker threads
* Zlib
* Other versions
* 26.x
* 25.x
* 24.x LTS
* 23.x
* 22.x LTS
* 21.x
* 20.x
* 19.x
* 18.x
* 17.x
* 16.x
* 15.x
* 14.x
* 13.x
* 12.x
* 11.x
* 10.x
* 9.x
* 8.x
* 7.x
* 6.x
* 5.x
* 4.x
* 0.12.x
* 0.10.x
*
Options
*
View on single page
*
View as JSON
* Edit on GitHub
Table of contents
* Query string
* querystring.decode()
* querystring.encode()
* querystring.escape(str)
* querystring.parse(str[, sep[, eq[, options]]])
* querystring.stringify(obj[, sep[, eq[, options]]])
* querystring.unescape(str)
Query string #
Source Code: lib/querystring.js
Stability: 2 - Stable
The node:querystring module provides utilities for parsing and formatting URL
query strings. It can be accessed using: const querystring = require ( 'node:querystring' ) ;
js copy
querystring is more performant than <URLSearchParams> but is not a
standardized API. Use <URLSearchParams> when performance is not critical or
when compatibility with browser code is desirable.
querystring.decode() #
Added in: v0.1.99
The querystring.decode() function is an alias for querystring.parse() .
querystring.encode() #
Added in: v0.1.99
The querystring.encode() function is an alias for querystring.stringify() .
querystring.escape(str) #
Added in: v0.1.25
* str <string>
The querystring.escape() method performs URL percent-encoding on the given
str in a manner that is optimized for the specific requirements of URL
query strings. The querystring.escape() method is used by querystring.stringify() and is
generally not expected to be used directly. It is exported primarily to allow
application code to provide a replacement percent-encoding implementation if
necessary by assigning querystring.escape to an alternative function.
querystring.parse(str[, sep[, eq[, options]]]) #
Added in: v0.1.25 History Version Changes v8.0.0 Multiple empty entries are now parsed correctly (e.g. &=&= ). v6.0.0 The returned object no longer inherits from Object.prototype . v6.0.0, v4.2.4 The eq parameter may now have a length of more than 1 .
* str <string> The URL query string to parse
* sep <string> The substring used to delimit key and value pairs in the
query string. Default: '&' .
* eq <string> . The substring used to delimit keys and values in the
query string. Default: '=' .
* options <Object>
* decodeURIComponent <Function> The function to use when decoding
percent-encoded characters in the query string. Default:
querystring.unescape() .
* maxKeys <number> Specifies the maximum number of keys to parse.
Specify 0 to remove key counting limitations. Default: 1000 .
The querystring.parse() method parses a URL query string ( str ) into a
collection of key and value pairs. For example, the query string 'foo=bar&abc=xyz&abc=123' is parsed into: {
" foo " : "bar" ,
" abc " : [ "xyz" , "123" ]
}
json copy
The object returned by the querystring.parse() method does not
prototypically inherit from the JavaScript Object . This means that typical
Object methods such as obj.toString() , obj.hasOwnProperty() , and others
are not defined and will not work . By default, percent-encoded characters within the query string will be assumed
to use UTF-8 encoding. If an alternative character encoding is used, then an
alternative decodeURIComponent option will need to be specified: // Assuming gbkDecodeURIComponent function already exists...
querystring . parse ( 'w=%D6%D0%CE%C4&foo=bar' , null , null ,
{ decodeURIComponent : gbkDecodeURIComponent } ) ;
js copy
querystring.stringify(obj[, sep[, eq[, options]]]) #
Added in: v0.1.25
* obj <Object> The object to serialize into a URL query string
* sep <string> The substring used to delimit key and value pairs in the
query string. Default: '&' .
* eq <string> . The substring used to delimit keys and values in the
query string. Default: '=' .
* options
* encodeURIComponent <Function> The function to use when converting
URL-unsafe characters to percent-encoding in the query string. Default:
querystring.escape() .
The querystring.stringify() method produces a URL query string from a
given obj by iterating through the object's "own properties". It serializes the following types of values passed in obj :
<string> | <number> | <bigint> | <boolean> | <string> [] | <number> [] | <bigint> [] | <boolean> []
The numeric values must be finite. Any other input values will be coerced to
empty strings. 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'
js copy
By default, characters requiring percent-encoding within the query string will
be encoded as UTF-8. If an alternative encoding is required, then an alternative
encodeURIComponent option will need to be specified: // Assuming gbkEncodeURIComponent function already exists,
querystring . stringify ( { w : '中文' , foo : 'bar' }, null , null ,
{ encodeURIComponent : gbkEncodeURIComponent } ) ;
js copy
querystring.unescape(str) #
Added in: v0.1.25
* str <string>
The querystring.unescape() method performs decoding of URL percent-encoded
characters on the given str . The querystring.unescape() method is used by querystring.parse() and is
generally not expected to be used directly. It is exported primarily to allow
application code to provide a replacement decoding implementation if
necessary by assigning querystring.unescape to an alternative function. By default, the querystring.unescape() method will attempt to use the
JavaScript built-in decodeURIComponent() method to decode. If that fails,
a safer equivalent that does not throw on malformed URLs will be used.
Links found on this page
- Skip to content [direct]
- Node.js [direct]
- About this documentation [direct]
- Usage and example [direct]
- Assertion testing [direct]
- Asynchronous context tracking [direct]
- Async hooks [direct]
- Buffer [direct]
- C++ addons [direct]
- C/C++ addons with Node-API [direct]
- C++ embedder API [direct]
- Child processes [direct]
- Cluster [direct]
- Command-line options [direct]
- Console [direct]
- Crypto [direct]
- Debugger [direct]
- Deprecated APIs [direct]
- Diagnostics Channel [direct]
- DNS [direct]
- Domain [direct]
- Environment Variables [direct]
- Errors [direct]
- Events [direct]
- File system [direct]
- FFI [direct]
- Globals [direct]
- HTTP [direct]
- HTTP/2 [direct]
- HTTPS [direct]
- Inspector [direct]
- Internationalization [direct]
- Iterable Streams API [direct]
- Modules: CommonJS modules [direct]
- Modules: ECMAScript modules [direct]
- Modules: node:module API [direct]
- Modules: Packages [direct]
- Modules: TypeScript [direct]
- Net [direct]
- OS [direct]
- Path [direct]
- Performance hooks [direct]
- Permissions [direct]
- Process [direct]
- Punycode [direct]
- Readline [direct]
- REPL [direct]
- Report [direct]
- Single executable applications [direct]
- SQLite [direct]
- Stream [direct]
- String decoder [direct]
- Test runner [direct]
- Timers [direct]
- TLS/SSL [direct]
- Trace events [direct]
- TTY [direct]
- UDP/datagram [direct]
- URL [direct]
- Utilities [direct]
- V8 [direct]
- Virtual File System [direct]
- VM [direct]
- WASI [direct]
- Web Crypto API [direct]
- Web Streams API [direct]
- Worker threads [direct]
- Zlib [direct]
- Code repository and issue tracker [direct]
- Index [direct]
- 26.x [direct]
- 25.x [direct]
- 24.x LTS [direct]
- 23.x [direct]
- 22.x LTS [direct]
- 21.x [direct]
- 20.x [direct]
- 19.x [direct]
- 18.x [direct]
- 17.x [direct]