Try using dns.lookup() method for URL validation. It worked fine for me. You have to pass it URL like this www.google.com or google.com. URL shouldn’t be like https://www.google.com coz this URL is considered invalid by it. My implementation is something like this
dns.lookup(<Your_url>, (err) => {
if (err) // Handle error
else {
// Save it to database with generate short url
}
})