How to use querystring

Comprehensive querystring code examples:

How to use querystring.encode:

321
322
323
324
325
326
327
328
329
330
    first_name: 'alex',
    email: 'alex@test.com'
  };
  const examples = integration.request.examples('123', '345', params).filter(example => example.headers['Content-Type'] != null ? example.headers['Content-Type'].match(/urlencoded$/) : undefined);
  for (const example of Array.from(examples)) {
    assert.equal(example.body, querystring.encode(params));
  }
});

it('should properly encode XML request body', () => {

How to use querystring.unescape:

228
229
230
231
232
233
234
235
236
237
238
module.exports = buildRequest
module.exports.TimeoutError = TimeoutError


function unixRequest (opts) {
  delete opts.port
  opts.socketPath = querystring.unescape(opts.hostname)
  delete opts.hostname
  return this.base.request(opts)
}

How to use querystring.escape:

1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
  res.status(200).send(responseData);
});

// Just a middle layer between the browser and the YouTube API so we can keep our API key private
app.get('/server/youtube', async function (req, res) {
  let searchTerms = querystring.escape(req.query.q);
  let apiKey = configAccessor.getYoutubeApiKey();

  let responseData = {};
  responseData.query = searchTerms;

How to use querystring.stringify:

135
136
137
138
139
140
141
142
143
144
let result = {};

try {
  const discovery = await utils.getOidcDiscovery();
  const response = await axios.post(discovery.token_endpoint,
    qs.stringify({
      client_id: config.get('oidc:clientId'),
      client_secret: config.get('oidc:clientSecret'),
      grant_type: 'refresh_token',
      refresh_token: refreshToken,

How to use querystring.parse:

242
243
244
245
246
247
248
249
250
251
req.on('data', chunk => {
  body += chunk.toString();
});

req.on('end', () => {
  let formData = qs.parse(body);
  if (formData.formType == 'pit') {
    res.end("WRONG FORM")
  } else if (formData.formType == 'main') {
    let stmt = `INSERT INTO main (event, season, name, team, match, level, game1, game2, game3, game4, game5, game6, game7, game8, game9, game10, game11, game12, game13, game14, game15, game16, game17, game18, game19, game20, game21, game22, game23, game24, game25, teleop, defend, driving, overall, discordID, discordName, discordTag, discordAvatarId, weight, analysis) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;