freeCodeCamp Challenge Guide: shorten url

Tell us what’s happening:
Describe your issue in detail here.

My project is working fine when I run it to replit. I think it’s due to a pre middleware of mongoose that I use. it’s not executed but should.

Your project link(s)


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15

Challenge: URL Shortener Microservice

Link to the challenge:

  1. 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;
  1. 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 format, the JSON response will contain { error: 'invalid url' }

  1. The redirect isn’t working. I didn’t really look at the code but the Request is pretty funky.
Request URL:'URL%20MongooseError:%20document%20must%20have%20an%20_id%20before%20saving

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

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.