Answers for "url.parse deprecated"

1

url.parse deprecated

// Get the url and parse
  const myUrl = new URL(req.url, "http://localhost:3000/");

  // Get url path
  const path = myUrl.pathname;
  const trimmedPath = path.replace(/^\/+|\/+$/g, "");
Posted by: Guest on June-02-2021
0

Get the url and parse or url.parse deprecated solved

// Get the url and parse
  // const parsedUrl = url.parse(req.url, true); --> This is deprecated
  const myUrl = new URL(req.url, "http://localhost:3000/"); // Use this instead

  // Get the path of the url
  const path = myUrl.pathname;
  const trimmedPath = path.replace(/\/+|\/+&/g, "");
  console.log(`Request is received on path: ${trimmedPath}`);
Posted by: Guest on April-18-2021

Code answers related to "url.parse deprecated"

Browse Popular Code Answers by Language