title: new URL() - WHATWG URL API
body: <p>I'm messing around with node and I'm trying to get an instance of the URL class (because of those handy properties). Like:</p>
  
  <pre><code>const { URL } = require('url');
  (...)
  http.createServer((request,response) =&gt; {
      let uri = new URL(request.url);
      (...)
  }
  </code></pre>
  
  <p>But it fails with</p>
  
  <pre><code>TypeError [ERR_INVALID_URL]: Invalid URL: /
  </code></pre>
  
  <p>It's funny because </p>
  
  <pre><code>const url = require('url');
  url.parse();
  </code></pre>
  
  <p>works. So I got curious about it. I understand this later method is older.</p>
  
  <p>I'm developing locally so to send a request I use localhost:8000 in the browser.</p>
  
  <p>How do I use the information in <code>request</code> to instantiate a new URL object?</p>
  
  <p>Info and things I've looked on already:</p>
  
  <pre><code>node -v
  v9.3.0
  
  https://nodejs.org/api/url.html#url_class_url
  https://stackoverflow.com/questions/44738065/uncaught-typeerror-url-is-not-a-constructor-using-whatwg-url-object-support-for
  https://stackoverflow.com/questions/45047840/in-node-js-how-to-get-construct-url-string-from-whatwg-url-including-user-and-pa
  https://stackoverflow.com/questions/47481784/does-url-parse-protect-against-in-a-url
  https://stackoverflow.com/questions/17184791/node-js-url-parse-and-pathname-property
  </code></pre>