サンプルコード
querystring
モジュールを使用する。
Node.jsの標準モジュールのため、事前準備等は不要。
const querystring = require('querystring');
// オブジェクト -> クエリ文字列
const obj = { a: '1', b: '2' };
const result1 = querystring.stringify(obj);
console.log(result1);
// => a=1&b=2
// クエリ文字列 -> オブジェクト
const str = 'a=1&b=2';
const result2 = querystring.parse(str);
console.log(result2);
// => [Object: null prototype] { a: '1', b: '2' }