You are not handling the URL validation correctly. Instead of doing what you are now, you can just use the URL constructor it has properties like hostname.
new URL(longUrl).hostname;
The response for invalid URLs is not the one that is asked for. It must match exactly.
If you pass an invalid URL that doesn’t follow the valid http://www.example.com format, the JSON response will contain { error: 'invalid url' }
The redirect isn’t working. I didn’t really look at the code but the Request is pretty funky.
It looks related to the warning about the _id in the URL model.
(node:1265) [MONGOOSE] Warning: mongoose: Cannot specify a custom index on `_id` for model name "Url", MongoDB does not allow overwriting the default `_id` index. See https://bit.ly/mongodb-id-index