SlideShare a Scribd company logo
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);
Query String Parameters & Methods in NodeJS.pptx
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

PPTX
Query String Parameters & Methods in NodeJS.pptx
PDF
Intro to JavaScript - Week 4: Object and Array
PPT
json.ppt download for free for college project
PPT
Json - ideal for data interchange
PPTX
21CS642 Module 3 Strings PPT.pptx VI SEM CSE
PPTX
Anton Dorfman. Shellcode Mastering.
PPTX
Shellcode mastering
PPTX
Static analysis: Around Java in 60 minutes
Query String Parameters & Methods in NodeJS.pptx
Intro to JavaScript - Week 4: Object and Array
json.ppt download for free for college project
Json - ideal for data interchange
21CS642 Module 3 Strings PPT.pptx VI SEM CSE
Anton Dorfman. Shellcode Mastering.
Shellcode mastering
Static analysis: Around Java in 60 minutes

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

PPTX
Single page application 05
PPTX
Getting Input from User
PPTX
Unit-2 Getting Input from User.pptx
PPTX
Programming in java basics
PPTX
Introduction to JcjfjfjfkuutyuyrsdterdfbvAVA.pptx
PPT
lecture 6 javascript event and event handling.ppt
PPTX
Level DB - Quick Cheat Sheet
PDF
Json the-x-in-ajax1588
PPTX
PDF
xml rpc
PPTX
Core java complete ppt(note)
PPTX
Class and Object.pptx from nit patna ece department
PDF
Class and Object JAVA PROGRAMMING LANG .pdf
PDF
Java Script
PPT
Java Script
PPT
JavaScript ppt for introduction of javascripta
PDF
Java Day-4
PPTX
5variables in c#
Single page application 05
Getting Input from User
Unit-2 Getting Input from User.pptx
Programming in java basics
Introduction to JcjfjfjfkuutyuyrsdterdfbvAVA.pptx
lecture 6 javascript event and event handling.ppt
Level DB - Quick Cheat Sheet
Json the-x-in-ajax1588
xml rpc
Core java complete ppt(note)
Class and Object.pptx from nit patna ece department
Class and Object JAVA PROGRAMMING LANG .pdf
Java Script
Java Script
JavaScript ppt for introduction of javascripta
Java Day-4
5variables in c#
Ad

More from HemaSenthil5 (16)

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

Recently uploaded (20)

PPTX
HR Introduction Slide (1).pptx on hr intro
DOCX
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
PDF
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
PPTX
New Microsoft PowerPoint Presentation - Copy.pptx
PPTX
Probability Distribution, binomial distribution, poisson distribution
PPTX
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
PDF
Laughter Yoga Basic Learning Workshop Manual
PPTX
ICG2025_ICG 6th steering committee 30-8-24.pptx
DOCX
Euro SEO Services 1st 3 General Updates.docx
PDF
Training And Development of Employee .pdf
PDF
Business model innovation report 2022.pdf
PPTX
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
PPTX
Lecture (1)-Introduction.pptx business communication
PDF
DOC-20250806-WA0002._20250806_112011_0000.pdf
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PDF
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
PDF
Dr. Enrique Segura Ense Group - A Self-Made Entrepreneur And Executive
PDF
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
PDF
A Brief Introduction About Julia Allison
DOCX
Business Management - unit 1 and 2
HR Introduction Slide (1).pptx on hr intro
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
New Microsoft PowerPoint Presentation - Copy.pptx
Probability Distribution, binomial distribution, poisson distribution
The Marketing Journey - Tracey Phillips - Marketing Matters 7-2025.pptx
Laughter Yoga Basic Learning Workshop Manual
ICG2025_ICG 6th steering committee 30-8-24.pptx
Euro SEO Services 1st 3 General Updates.docx
Training And Development of Employee .pdf
Business model innovation report 2022.pdf
Dragon_Fruit_Cultivation_in Nepal ppt.pptx
Lecture (1)-Introduction.pptx business communication
DOC-20250806-WA0002._20250806_112011_0000.pdf
COST SHEET- Tender and Quotation unit 2.pdf
20250805_A. Stotz All Weather Strategy - Performance review July 2025.pdf
Dr. Enrique Segura Ense Group - A Self-Made Entrepreneur And Executive
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
A Brief Introduction About Julia Allison
Business Management - unit 1 and 2

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);
  • 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..