Node.js querystring.encode() Function Last Updated : 08 Mar, 2021 Comments Improve Suggest changes Like Article Like Report The querystring.encode() method is used to produce a URL query string from the given object that contains the key-value pairs. The method iterates through the object’s own properties to generate the query string. It can serialize a single or an array of strings, numbers, and boolean. Any other types of values are coerced to empty strings. During serializing, the UTF-8 encoding format is used to encode any character that requires percent-encoding. To encode using an alternative character encoding, the encodeURIComponent option has to be specified. Syntax: querystring.encode( obj, sep, eq, options ) Parameters: This function accepts four parameters as mentioned above and described below: obj: Object that has to be serialized into the URL query string.sep: String that specifies the substring used to delimit the key and value pairs in the query string. The default value is “&”.eq: String that specifies the substring used to delimit keys and values in the query string. The default value is “=”.options: It is an Object which can be used to modify the behavior of the method. It has the following parameters:encodeURIComponent: It is a function that would be used to convert URL-unsafe characters to percent-encoding in the query string. The default value is querystring.escape(). Return Value: It returns a String that contains the URL query produced from the given object. Example 1: JavaScript const querystring = require('querystring'); let obj = { user: "pratik", isMale: true, role: ["admin", "editor", "manager"], } let output = querystring.encode(obj); console.log("Output: ", output); Output: Example 2: JavaScript const querystring = require('querystring'); let obj = { user: "pratik", isMale: true, role: ["admin", "editor", "manager"], } let output = querystring.encode(obj, '/', '->'); console.log("Output: ", output); Output: Reference:https://nodejs.org/api/querystring.html#querystring_querystring_encode Comment More infoAdvertise with us Next Article Node.js querystring.encode() Function P pratikraut0000 Follow Improve Article Tags : Technical Scripter Web Technologies Node.js NodeJS-function Node.js- querystring-Module +1 More Similar Reads Node.js MySQL SUBSTRING() Function SUBSTRING() function is a built-in function in MySQL that is used to get a substring of input string between given range inclusive. Syntax: SUBSTRING(input_string, from, length)Parameters: It takes three parameters as follows: input_string: It is the given string for which the substring will be exec 2 min read Node.js Query String The Query String module used to provides utilities for parsing and formatting URL query strings. It can be used to convert query string into JSON object and vice-versa. Node.js Query StringQuery strings in Node.js are a common way to pass data to a server via a URL. A query string is the part of a U 2 min read Node.js Query String Complete Reference Node.js query String module is used as utilities for parsing and formatting URL query strings. It can be used to convert query string into JSON object and vice-versa. Example: JavaScript // Import the querystring module const querystring = require("querystring"); // Specify the URL query s 1 min read Node.js MySQL TRIM() Function TRIM() function is a built-in function in MySQL that is used to trim all spaces from both sides of the input string. Syntax: TRIM(string)Parameters: It takes one parameter as follows: string: It is the string to be trimmed from both sides.Return Value: It returns string after trimming from both side 2 min read Node.js querystring.parse() Method The querystring.parse() method is used to parse a URL query string into an object that contains the key and pair values of the query URL. The object returned does not inherit prototypes from the JavaScript object, therefore usual Object methods will not work. During parsing, the UTF-8 encoding forma 3 min read Like