xxxxxxxxxx
// Importing the 'query-string' package
const queryString = require('query-string');
// Parsing a query string
const parsedQuery = queryString.parse('?name=John&age=25');
// Accessing query parameters
console.log(parsedQuery.name); // Output: John
console.log(parsedQuery.age); // Output: 25
// Stringifying an object into a query string
const obj = { page: 'home', count: 10 };
const stringifiedQuery = queryString.stringify(obj);
console.log(stringifiedQuery); // Output: 'page=home&count=10'
xxxxxxxxxx
// Importing the required module
const querystring = require('querystring');
// Sample query string
const queryString = 'name=John&age=30&location=USA';
// Parsing the query string
const parsedQuery = querystring.parse(queryString);
// Accessing specific query parameters
const name = parsedQuery.name;
const age = parsedQuery.age;
const location = parsedQuery.location;
// Logging the parsed values
console.log('Name:', name);
console.log('Age:', age);
console.log('Location:', location);