Back End Development and APIs Projects - URL Shortener Microservice

Tell us what’s happening:
Describe your issue in detail here.
I keep failing the second and third tests:

  • You can POST a URL to /api/shorturl and get a JSON response with original_url and short_url properties. Here’s an example: { original_url : 'https://freeCodeCamp.org', short_url : 1}

  • Failed:When you visit /api/shorturl/<short_url>, you will be redirected to the original URL.
    Your project link(s)

solution:

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36

Challenge: Back End Development and APIs Projects - URL Shortener Microservice

Link to the challenge:

You are crashing.

You probably just don’t notice it because the Replit is restarting. Add --watch to the node start script "start": "node --watch index.js" so you can see the error ReferenceError: urls is not defined

You are using the identifier urls that doesn’t exist. You have no such data structure or model/document.

I have now updated it to connect to the mongoose document.

However, I am now getting this error:

TypeError: Cannot read properties of undefined (reading ‘startsWith’)
at connectionStringHasValidScheme (/home/runner/boilerplate-project-urlshortener/node_modules/mongodb-connection-string-url/lib/index.js:9:30)
at new ConnectionString (/home/runner/boilerplate-project-urlshortener/node_modules/mongodb-connection-string-url/lib/index.js:85:34)
at parseOptions (/home/runner/boilerplate-project-urlshortener/node_modules/mongodb/lib/connection_string.js:191:17)
at new MongoClient (/home/runner/boilerplate-project-urlshortener/node_modules/mongodb/lib/mongo_client.js:48:63)
at Object. (/home/runner/boilerplate-project-urlshortener/index.js:9:16)
at Module._compile (node:internal/modules/cjs/loader:1159:14)

If you are not going to use the Mongoose connection method that was taught in the curriculum you will have to do your own research.

Also, remember to use the Replit secrets to add the environment variable.

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