node legacy url.parse deprecated, what to use instead?

const server = http.createServer((req, res) => {
   const baseURL =  req.protocol + '://' + req.headers.host + "https://stackoverflow.com/";
   const reqUrl = new URL(req.url,baseURL);
   console.log(reqUrl);
});

will give reqUrl :

URL {
  href: 'http://127.0.0.1:3000/favicon.ico',
  origin: 'http://127.0.0.1:3000',
  protocol: 'http:',
  username: '',
  password: '',
  host: '127.0.0.1:3000',
  hostname: '127.0.0.1',
  port: '3000',
  pathname: '/favicon.ico',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)