Home >>Nodejs Tutorial >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.
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. |
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);
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);