An important part of programming is testing the code so its outcome is as you expected to be.
Can you type a couple of examples of invalid URL you have tried so far?
Another thing I have noticed is that when I keep inserting the same URL over and over again, it’s short version keeps changing as well. That’s a waste of storage space, don’t you think?
const url = require('url').URL;
const url2 = new url(urlToShorten);
You are relying on a functionality of the URL module which relies on a correct input
and is not solely made for a purpose of verifying correct web address URL.
The required format is http://www.example.com or https://www.example.com
but your API also accepts URL like C://hello.txt.
You need to ensure that the format is correct yourself. And when you do that, you don’t even need the url module for that.