home PYTHONJAVA
 

Node.js Query Strings


The Node.js Query String gives methods to bargain query string. It tends to be utilized to change over query string into JSON object and bad habit versa.

To use query string module, you have to utilize require('querystring').

Node.js Query String Methods

The Node.js Query String utility has four strategies. The two significant techniques are given below.

Method Description
querystring.parse(str[, sep][, eq][, options]) converts query string into JSON object.
querystring.stringify(obj[, sep][, eq][, options]) converts JSON object into query string.

Node.js Query String Example 1: parse()

Let's see a straightforward case of Node.js Query String parse() method.

File: query string-example1.js

  1. querystring = require('querystring');  
  2. const obj1=querystring.parse('name=sonoo&company=Welookups');  
  3. console.log(obj1);  

Node.js Query String Example 1: parse()

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

File: query-string-example1.js

  1. querystring = require('querystring');  
  2. const obj1=querystring.parse('name=sonoo&company=Welookups');  
  3. console.log(obj1);  

Node.js Query String Example 2: stringify()

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

File: query-string-example2.js

  1. querystring = require('querystring');  
  2. const qs1=querystring.stringify({name:'sonoo',company:'Welookups'});  
  3. console.log(qs1);  





welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.