The test are showing Timed out even if the codes are perfect

In the certification projects whenever I’m posting a project its showing You can POST a URL to /api/shorturl/new and get a JSON response with original_url and short_url properties. Here’s an example: { original_url : '', short_url : 1}

When you visit /api/shorturl/<short_url> , you will be redirected to the original URL.

If you pass an invalid URL that doesn’t follow the valid format, the JSON response will contain { error: 'invalid url' }

Your project link(s)


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36.

Challenge: URL Shortener Microservice

Link to the challenge:

Welcome, there.

The tests are timing out, as far as I can see, which suggests there is a bug in your code causing your app to stall.

A quick change which might help is to move the app.listen call to the bottom of the script.

Hope this helps

thank you for replying but I’m sorry to inform you
that the codes are still not working

Here is a rundown of some things that need fixing:

  1. Remove the middleware body-parser. Use express.json() instead (not within the callback)
  2. This is far too complicated, and will likely cause tests to fail:
let urlRegex = new RegExp(/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)?/gi)
  1. A global responseObject is likely to cause unexpected behaviour, as the tests run multiple requests, and each one could compound onto the next request.

Hope this helps

Thank you soo much [Sky020] It actually helped me a lot