The tutorial provides the details on the node.js query string usage. The node.js query string provides different methods for the string manipulation. The node.js Query String allows to convert the string to JSON Object and JSON Object and be converted to Query String . The node.js Query String can be accessed using the command
const querystring = require('querystring');
Node.js Query String Methods
The below given are the available methods using Query String in node.js
Query String Method Name | Query String Method Description |
querystring.decode() | alias function for querystring.parse() |
querystring.encode() | alias function for querystring.stringify() |
querystring.escape(str) | performs URL percent-encoding on the given string to proivde optimized URL query strings str – <string> |
querystring.unescape(str) | performs decoding of URL percent-encoded characters on the given str- <string> |
querystring.parse(str[, sep][, eq][, options]) | parses a URL query string (str) into a collection of key and value pairs str – <string> – URL query string sep -<string> – substring used to delimit key and value pairs in the query string. Default: ‘&’. eq – <string> – substring used to delimit keys and values in the query string. Default: ‘=’. options – <object> where decodeURIComponent – performs decoding percent-encoded characters in the query string. Default: querystring.unescape(). maxKeys – indicates maximum number of keys to parse. Specify 0 to remove key counting limitations. Default: 1000 |
querystring.stringify(obj[, sep][, eq][, options]) | provides URL query string from the object by iterating the object’s properties obj – – serialized URL query string sep – – substring used to delimit key and value pairs in the query string. Default: ‘&’. eq – – substring used to delimit keys and values in the query string. Default: ‘=’. options – where encodeURIComponent – performs when converting URL-unsafe characters to percent-encoding in the query string. Default: querystring.escape() |
querystring = require('querystring'); const queryObject=querystring.parse('name=mohitsharma&company=oracleappshelp.com'); console.log(queryObject);
C:\Users\user\Desktop >node querystring.js [Object: null prototype ]{ name: "mohitsharma", company: 'oracleappshelp.com' }