How to replace querystring.stringify with URLSearchParams?

        querystring.stringify({
          error: 'error_status'
        })

‘querystring’ is deprecated, how would I replace it with the native URLSearchParams here?

>Solution :

const params = new URLSearchParams({
  error: 'error_status'
});

console.log(params.toString());
// error=error_status

console.log(`?${params.toString()}`);
// ?error=error_status

More information at https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams

Leave a Reply