How can I parse successfully www.stackoverflow.com as a URL using the WHATWG URL API in NodeJS?
If I try new URL("www.stackoverflow.com") I get the error error:
URL constructor: www.stackoverflow.com is not a valid URL.
Note: url.parse is deprecated
Simply do this:
const parsedURL = new URL(url.startsWith("http") ? url : `https://${url}`);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With