Node.js Query String Tutorial

The Node.js Query String provides methods to deal with query string. It can be used to convert query string into JSON object and vice-versa.

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

Node.js Query String Methods

  • 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()

    querystring = require('querystring');  
    const obj1=querystring.parse('name=java&aim=tutorial');  

    Node.js Query String Example 2: stringify()

    querystring = require('querystring');  
    const qs1=querystring.stringify({name:'java',company:'tutorial'});  

    © copyright 2017-2022 Completedone pvt ltd.