📜  获取 url 并解析或 url.parse 已弃用已解决 - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:05.107000             🧑  作者: Mango

代码示例1
// 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}`);