Back End Development and APIs Projects - URL Shortener Microservice

Tell us what’s happening:
My tests are timing out, but the application is working for me when I test it myself.

Your project link(s)

solution: boilerplate-project-urlshortener - Replit

Your browser information:

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

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

Link to the challenge:

I’ve logged the route inputs and the then clause of your POST:

req.body: {"url":""}
req.params: {}
req.query: {}
doc: null
TypeError: Cannot read property 'original_url' of null
    at /home/runner/boilerplate-project-urlshortener-25/index.js:86:29
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

So, where you think you have a document, you have null. I didn’t track down where that’s happening, but it’s either in the DB configuration and access or to do with your shortenUrl helper being asynchronous but not being called that way. Your other helper function has the same problem.

I would examine the DB configuration and possibly use mongoose like in the practice exercises for a simpler approach. If you are actually getting the documents running the project manually, then it’s most likely the inconsistent async handling. You’ll need to handle all the async DB calls like findOneAndUpdate() and findOne() or you’ll get unresolved promises returned instead of your data.

Thank you, finally got it working.

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