Home >>Nodejs Tutorial >Node.js Query String

Node.js Query String

Node.js Query String

The Query String for Node.js provides methods to handle query string. Using it to convert query string to JSON object and vice versa.

You need to use require('querystring) 'for query string module.

Node.js Query String Methods

There are four methods to the Node.js Query String utility. The two significant approaches are described below.

Method Description
querystring.parse(str[, sep][, eq][, options]) Conversion of query string to JSON object
querystring.stringify(obj[, sep][, eq][, options]) Converts object JSON to query string.

Node.js Query String Example 1: parse()

Let's see a basic example of a parse() method for the Node.js Query String.

File: query-string-example1.js

querystring = require('querystring');  
const par1=querystring.parse('name=training&company=phptpoint');  
console.log(par1); 

Nodejs query String

Node.js Query String Example 2: stringify()

Let's see a basic example of a stringify() method for the Node.js Query String.

File: query-string-example2.js

querystring = require('querystring');  
const par2=querystring.stringify({name:'training',company:'phptpoint'});  
console.log(par2);  

Nodejs query String


No Sidebar ads