Try to add this line:
var URL = require('url').URL;
The full example is here:
var URL = require('url').URL;
var myURL = new URL('http://www.example.com/foo?bar=1#main');
console.log(myURL.host);
// prints 'www.example.com'
All of those are from this amazing tutorial.