SlideShare a Scribd company logo
1 of 12
Query String Parameters &
Methods in NodeJS
What is Query String in NodeJS
• There are ways to deal with query strings to the Node.js Query
String. It can transform a query string into a JSON object and the
other way around.
• Now, there are methods for parsing and formatting URL query strings
available in the Node.js query string module. The following command
will access the query string module:
• const querystring = require(‘querystring’);
var url = require('url');
var my_url = 'http://localhost:3000/index.htm?year=2020&month=May';
//Parsing the adress:
var que = url.parse(my_url, true);
//The parsing method has created an object that can be accessed using its property
names.
console.log("Host: "+ que.host);
console.log("PathName: "+que.pathname);
console.log("Search Query: "+que.search);
console.log("Protocol: "+que.protocol);
console.log("Href: "+que.href);
//You can find about the month inside the query by storing it inside a variable and
later accessing its properties.
var que_info = que.query;
console.log("Year: "+ que_info.year);
In NodeJS the following are the six Query
String Parameters listed below.
• decode()
• encode()
• escape(str)
• parse(str[, sep[, eq[, options]]])
• stringify(obj[, sep[, eq[, options]]])
• unescape(str)
Query String methods in NodeJS with
Description
querystring.parse() Method in NodeJS
• The URL query string is parsed into an object with a key-value pair
using the querystring.parse() function.
• We cannot utilize Object methods like obj.toString or
obj.hasOwnProperty since the object we receive is not a JavaScript
object ().
• The syntax for the method is below.
• querystring.parse( str[, sep[, eq[, options]]]) )
• The syntax for the method is below.
• querystring.parse( str[, sep[, eq[, options]]]) )
• As seen from the above syntax this method accepts four parameters, which
are described below.
• str: This is the only required string field and it specifies in the query string that
has to be parsed.
• sep: If provided, it is an optional string parameter that specifies the substring that
will be used to separate the query string’s key and value pairs. The default value
used is “&”.
• eq: It is an optional string field that is used in the query string to separate the keys
from the values. The default value used is “=”.
• options: It is an optional object field that is used to modify the behavior of the
method. It can have the following parameters:
• decodeURIComponent: It is a function that would be used to provide the query string’s
encoding format. The default setting is querystring.unescape(), about which we will learn
later.
• maxKeys: This value indicates how many keys in total should be processed. Any number of
keys can be parsed if the value is set to “0,” which eliminates any counting restrictions. The
default setting is “1000.”
querystring.stringify() Method in NodeJS
• A supplied object that has a key-value pair can be utilized to create a
query string using the querystring.stringify() method. When compared
to querystring.parse(), it is the exact opposite.
• The string, integer, and Boolean values for the key can all be
converted using it. An array of strings, numbers, or Boolean values
can also be used as values. Serialization is the process of converting an
object to a query string.
• Unless we indicate an alternative encoding format, the most recent
UTF-8 encoding format is taken into account. But since UTF-8
encoding is the industry standard and includes all international
characters,
• The syntax for the method is below.
• querystring. stringify( obj[, sep[, eq[, options]]]) )
• The method accepts four parameters, which are specified below, as can be seen
from the syntax above.
• obj: The sole object field that is necessary defines the object that has to be
serialized.
• sep: It is a string field that is optional and, if provided, provides the substring that
will be used to separate the key and value pairs in the query string. “&” is the
default value, which is typically used.
• eq: The substring used to separate the query string’s keys and values are specified
in this optional string parameter. In most cases, the default value is “=”.
• options: It is an optional object field that is used to change how the method
behaves. It can have the following parameters:
• decodeURIComponent: It is a function that would be utilized to specify the query string’s
encoding format. The default value is querystring.escape(), about which we will learn later.
querystring.encode() Method in NodeJS
• A simple alias for the querystring.stringify() technique is querystring.encode(). We can use it in our
stringify example. Add the following code to the querystring.js file we previously established.
• // Import the querystring module
• const querystring = require(“querystring”);
• // Name the object that required serialisation.
• let obj = {
• name: “nabendu”,
• access: true,
• role: [“developer”, “architect”, “manager”],
• };
• // Use the stringify() method on the object
• let queryString = querystring.encode(obj);
• console.log(“Query String 1:”, queryString);
• Run the terminal command node querystring.js like we did earlier. And the results will match those
of the querystring.stringify() function.
• Query String 1: name=nabendu&access=true&role=developer&role=architect&role=manager
querystring.decode() Method in NodeJS
• A simple alias for the querystring.parse() function is querystring.decode().
We can use it in our parsing example. Add the following code to the
querystring.js file we previously established.
• // Import the querystring module
• const querystring = require(“querystring”);
• // Specify this URL query string to be parsed
• let urlQueryString =
“name=nabendu&units=kgs&units=pounds&login=false”;
• // Use the parse() method on the string
• let parsedObj = querystring.decode(urlQueryString);
• console.log(“Parsed Query 1:”, parsedObj);
• Run the node querystring.js command from a terminal, as you did before.
The result will be identical to that of the querystring.parse() function.
• Parsed Query 1: [Object: null prototype] { name: ‘bhanu’, units: [ ‘kgs’,
‘pounds’ ], login: ‘false’ }
• querystring.escape(str) Method in NodeJS
• The querystring.escape() function is typically only utilised by the
querystring.stringify() method.
• f.querystring.unescape(str) Method
• The querystring.unescape() method is often only utilised by the
querystring.parse() method..

More Related Content

Similar to Query String Parameters & Methods in NodeJS.pptx

Similar to Query String Parameters & Methods in NodeJS.pptx (20)

Single page application 05
Single page application   05Single page application   05
Single page application 05
 
Getting Input from User
Getting Input from UserGetting Input from User
Getting Input from User
 
Unit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptxUnit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptx
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
c++ UNIT II.pptx
c++ UNIT II.pptxc++ UNIT II.pptx
c++ UNIT II.pptx
 
Level DB - Quick Cheat Sheet
Level DB - Quick Cheat SheetLevel DB - Quick Cheat Sheet
Level DB - Quick Cheat Sheet
 
Json the-x-in-ajax1588
Json the-x-in-ajax1588Json the-x-in-ajax1588
Json the-x-in-ajax1588
 
Aspdot
AspdotAspdot
Aspdot
 
xml rpc
xml rpcxml rpc
xml rpc
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Java Script
Java ScriptJava Script
Java Script
 
Java Script
Java ScriptJava Script
Java Script
 
Java Day-4
Java Day-4Java Day-4
Java Day-4
 
5variables in c#
5variables in c#5variables in c#
5variables in c#
 
2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers2CPP06 - Arrays and Pointers
2CPP06 - Arrays and Pointers
 
Lecture 3.pptx
Lecture 3.pptxLecture 3.pptx
Lecture 3.pptx
 
Дмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI векеДмитрий Нестерук, Паттерны проектирования в XXI веке
Дмитрий Нестерук, Паттерны проектирования в XXI веке
 
Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C language
 
Avro intro
Avro introAvro intro
Avro intro
 
WEB-MODULE 4.pdf
WEB-MODULE 4.pdfWEB-MODULE 4.pdf
WEB-MODULE 4.pdf
 

More from HemaSenthil5

DBMS-Recovery techniques dfggrjfchdfhwrshfxbvdgtytdfx.pptx
DBMS-Recovery techniques dfggrjfchdfhwrshfxbvdgtytdfx.pptxDBMS-Recovery techniques dfggrjfchdfhwrshfxbvdgtytdfx.pptx
DBMS-Recovery techniques dfggrjfchdfhwrshfxbvdgtytdfx.pptx
HemaSenthil5
 
Buffer Management in DBMS systemsss.pptx
Buffer Management in DBMS systemsss.pptxBuffer Management in DBMS systemsss.pptx
Buffer Management in DBMS systemsss.pptx
HemaSenthil5
 
Usability evaluation for Business Intelligence applications.pptx
Usability  evaluation  for  Business  Intelligence  applications.pptxUsability  evaluation  for  Business  Intelligence  applications.pptx
Usability evaluation for Business Intelligence applications.pptx
HemaSenthil5
 
godds-servicescontinuum-151010201328-lva1-app6891 (1).pptx
godds-servicescontinuum-151010201328-lva1-app6891 (1).pptxgodds-servicescontinuum-151010201328-lva1-app6891 (1).pptx
godds-servicescontinuum-151010201328-lva1-app6891 (1).pptx
HemaSenthil5
 
business intelligence of its important Teams.pptx
business intelligence of its important Teams.pptxbusiness intelligence of its important Teams.pptx
business intelligence of its important Teams.pptx
HemaSenthil5
 
Big Data Mining Methods in Medical Applications [Autosaved].pptx
Big Data Mining Methods in Medical Applications [Autosaved].pptxBig Data Mining Methods in Medical Applications [Autosaved].pptx
Big Data Mining Methods in Medical Applications [Autosaved].pptx
HemaSenthil5
 
module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...
HemaSenthil5
 

More from HemaSenthil5 (16)

DBMS-Recovery techniques dfggrjfchdfhwrshfxbvdgtytdfx.pptx
DBMS-Recovery techniques dfggrjfchdfhwrshfxbvdgtytdfx.pptxDBMS-Recovery techniques dfggrjfchdfhwrshfxbvdgtytdfx.pptx
DBMS-Recovery techniques dfggrjfchdfhwrshfxbvdgtytdfx.pptx
 
Buffer Management in DBMS systemsss.pptx
Buffer Management in DBMS systemsss.pptxBuffer Management in DBMS systemsss.pptx
Buffer Management in DBMS systemsss.pptx
 
Usability evaluation for Business Intelligence applications.pptx
Usability  evaluation  for  Business  Intelligence  applications.pptxUsability  evaluation  for  Business  Intelligence  applications.pptx
Usability evaluation for Business Intelligence applications.pptx
 
godds-servicescontinuum-151010201328-lva1-app6891 (1).pptx
godds-servicescontinuum-151010201328-lva1-app6891 (1).pptxgodds-servicescontinuum-151010201328-lva1-app6891 (1).pptx
godds-servicescontinuum-151010201328-lva1-app6891 (1).pptx
 
Enterprize and departmental BusinessIintelligence.pptx
Enterprize and departmental BusinessIintelligence.pptxEnterprize and departmental BusinessIintelligence.pptx
Enterprize and departmental BusinessIintelligence.pptx
 
MODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.ppt
MODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.pptMODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.ppt
MODULE 3 -Normalization bwdhwbifnweipfnewknfqekndd_1.ppt
 
BI STRATEGY and tactical analytics .pptx
BI STRATEGY and tactical analytics .pptxBI STRATEGY and tactical analytics .pptx
BI STRATEGY and tactical analytics .pptx
 
MODULE 3 -Normalization_1.ppt moduled in design
MODULE 3 -Normalization_1.ppt moduled in designMODULE 3 -Normalization_1.ppt moduled in design
MODULE 3 -Normalization_1.ppt moduled in design
 
IT6010-BUSINESS-INTELLIGENCE-Question-Bank_watermark.pdf
IT6010-BUSINESS-INTELLIGENCE-Question-Bank_watermark.pdfIT6010-BUSINESS-INTELLIGENCE-Question-Bank_watermark.pdf
IT6010-BUSINESS-INTELLIGENCE-Question-Bank_watermark.pdf
 
business intelligence of its important Teams.pptx
business intelligence of its important Teams.pptxbusiness intelligence of its important Teams.pptx
business intelligence of its important Teams.pptx
 
Big Data Mining Methods in Medical Applications [Autosaved].pptx
Big Data Mining Methods in Medical Applications [Autosaved].pptxBig Data Mining Methods in Medical Applications [Autosaved].pptx
Big Data Mining Methods in Medical Applications [Autosaved].pptx
 
Internet-of-Things-for-Sm.9272728.powerpoint.pptx
Internet-of-Things-for-Sm.9272728.powerpoint.pptxInternet-of-Things-for-Sm.9272728.powerpoint.pptx
Internet-of-Things-for-Sm.9272728.powerpoint.pptx
 
Business Models.pptx Download millions of presentations
Business Models.pptx Download millions of presentationsBusiness Models.pptx Download millions of presentations
Business Models.pptx Download millions of presentations
 
Node js installation steps.pptx slide share ppts
Node js installation steps.pptx slide share pptsNode js installation steps.pptx slide share ppts
Node js installation steps.pptx slide share ppts
 
module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...
 
iot health applications.pptx
iot health applications.pptxiot health applications.pptx
iot health applications.pptx
 

Recently uploaded

Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
lizamodels9
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
lizamodels9
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
daisycvs
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
lizamodels9
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
amitlee9823
 

Recently uploaded (20)

Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
Call Girls From Pari Chowk Greater Noida ❤️8448577510 ⊹Best Escorts Service I...
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptx
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
 
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
 
Falcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to ProsperityFalcon's Invoice Discounting: Your Path to Prosperity
Falcon's Invoice Discounting: Your Path to Prosperity
 
Falcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in indiaFalcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in india
 
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
Quick Doctor In Kuwait +2773`7758`557 Kuwait Doha Qatar Dubai Abu Dhabi Sharj...
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 

Query String Parameters & Methods in NodeJS.pptx

  • 1. Query String Parameters & Methods in NodeJS
  • 2. What is Query String in NodeJS • There are ways to deal with query strings to the Node.js Query String. It can transform a query string into a JSON object and the other way around. • Now, there are methods for parsing and formatting URL query strings available in the Node.js query string module. The following command will access the query string module: • const querystring = require(‘querystring’);
  • 3. var url = require('url'); var my_url = 'http://localhost:3000/index.htm?year=2020&month=May'; //Parsing the adress: var que = url.parse(my_url, true); //The parsing method has created an object that can be accessed using its property names. console.log("Host: "+ que.host); console.log("PathName: "+que.pathname); console.log("Search Query: "+que.search); console.log("Protocol: "+que.protocol); console.log("Href: "+que.href); //You can find about the month inside the query by storing it inside a variable and later accessing its properties. var que_info = que.query; console.log("Year: "+ que_info.year);
  • 4.
  • 5. In NodeJS the following are the six Query String Parameters listed below. • decode() • encode() • escape(str) • parse(str[, sep[, eq[, options]]]) • stringify(obj[, sep[, eq[, options]]]) • unescape(str)
  • 6. Query String methods in NodeJS with Description querystring.parse() Method in NodeJS • The URL query string is parsed into an object with a key-value pair using the querystring.parse() function. • We cannot utilize Object methods like obj.toString or obj.hasOwnProperty since the object we receive is not a JavaScript object (). • The syntax for the method is below. • querystring.parse( str[, sep[, eq[, options]]]) )
  • 7. • The syntax for the method is below. • querystring.parse( str[, sep[, eq[, options]]]) ) • As seen from the above syntax this method accepts four parameters, which are described below. • str: This is the only required string field and it specifies in the query string that has to be parsed. • sep: If provided, it is an optional string parameter that specifies the substring that will be used to separate the query string’s key and value pairs. The default value used is “&”. • eq: It is an optional string field that is used in the query string to separate the keys from the values. The default value used is “=”. • options: It is an optional object field that is used to modify the behavior of the method. It can have the following parameters: • decodeURIComponent: It is a function that would be used to provide the query string’s encoding format. The default setting is querystring.unescape(), about which we will learn later. • maxKeys: This value indicates how many keys in total should be processed. Any number of keys can be parsed if the value is set to “0,” which eliminates any counting restrictions. The default setting is “1000.”
  • 8. querystring.stringify() Method in NodeJS • A supplied object that has a key-value pair can be utilized to create a query string using the querystring.stringify() method. When compared to querystring.parse(), it is the exact opposite. • The string, integer, and Boolean values for the key can all be converted using it. An array of strings, numbers, or Boolean values can also be used as values. Serialization is the process of converting an object to a query string. • Unless we indicate an alternative encoding format, the most recent UTF-8 encoding format is taken into account. But since UTF-8 encoding is the industry standard and includes all international characters,
  • 9. • The syntax for the method is below. • querystring. stringify( obj[, sep[, eq[, options]]]) ) • The method accepts four parameters, which are specified below, as can be seen from the syntax above. • obj: The sole object field that is necessary defines the object that has to be serialized. • sep: It is a string field that is optional and, if provided, provides the substring that will be used to separate the key and value pairs in the query string. “&” is the default value, which is typically used. • eq: The substring used to separate the query string’s keys and values are specified in this optional string parameter. In most cases, the default value is “=”. • options: It is an optional object field that is used to change how the method behaves. It can have the following parameters: • decodeURIComponent: It is a function that would be utilized to specify the query string’s encoding format. The default value is querystring.escape(), about which we will learn later.
  • 10. querystring.encode() Method in NodeJS • A simple alias for the querystring.stringify() technique is querystring.encode(). We can use it in our stringify example. Add the following code to the querystring.js file we previously established. • // Import the querystring module • const querystring = require(“querystring”); • // Name the object that required serialisation. • let obj = { • name: “nabendu”, • access: true, • role: [“developer”, “architect”, “manager”], • }; • // Use the stringify() method on the object • let queryString = querystring.encode(obj); • console.log(“Query String 1:”, queryString); • Run the terminal command node querystring.js like we did earlier. And the results will match those of the querystring.stringify() function. • Query String 1: name=nabendu&access=true&role=developer&role=architect&role=manager
  • 11. querystring.decode() Method in NodeJS • A simple alias for the querystring.parse() function is querystring.decode(). We can use it in our parsing example. Add the following code to the querystring.js file we previously established. • // Import the querystring module • const querystring = require(“querystring”); • // Specify this URL query string to be parsed • let urlQueryString = “name=nabendu&units=kgs&units=pounds&login=false”; • // Use the parse() method on the string • let parsedObj = querystring.decode(urlQueryString); • console.log(“Parsed Query 1:”, parsedObj); • Run the node querystring.js command from a terminal, as you did before. The result will be identical to that of the querystring.parse() function. • Parsed Query 1: [Object: null prototype] { name: ‘bhanu’, units: [ ‘kgs’, ‘pounds’ ], login: ‘false’ }
  • 12. • querystring.escape(str) Method in NodeJS • The querystring.escape() function is typically only utilised by the querystring.stringify() method. • f.querystring.unescape(str) Method • The querystring.unescape() method is often only utilised by the querystring.parse() method..