I am trying to decode a URL and also format it with URL module in nodejs.
const url = require('url');
const oldUrl = "https://tut.by/ad=%24%7Baccount.domain%7D";
const newUrl = url.parse(oldUrl, true).format();
Here is the returned value for newUrl
{
auth: null
hash: null
host: "tut.by"
hostname: "tut.by"
href: "https://tut.by/?ad=%24%7Baccount.domain%7D"
path: "/?ad=%24%7Baccount.domain%7D"
pathname: "/"
port: null
protocol: "https:"
query: {ad: "${account.domain}"}
search: "?ad=%24%7Baccount.domain%7D"
slashes: true
}
When I finally format it like this:
const formattedUrl = newUrl.format();
It returned:
https://tut.by/?ad=%24%7Baccount.domain%7D
But the expected result is:
https://tut.by/?ad=${account.domain}
How to handle this situation so it returns the correctly decoded URL?