Back End Development and APIs Projects - Timestamp Microservice

My get route:

app.get('/api/:date?', function (req, res) {
  let date = req.params.date;
  let myDate = !date
    ? new Date()
    : new Date(isNum(date) ? parseInt(date) : date);
  let utc = myDate.toUTCString();
  let unix = myDate.getTime();
  res.json(
    utc === 'Invalid Date'
      ? { error: 'Invalid date' }
      : { unix, utc }
  );
});

When I run the tests, I get this:
An empty date parameter should return the current time in a JSON object with a unix key An empty date parameter should return the current time in a JSON object with a utc key

https://fcc-timestamp-cmum.onrender.com/api

When I visit my api with no date param I get this response.
{“unix”:1703710982628,“utc”:“Wed, 27 Dec 2023 21:03:02 GMT”}

My repo: GitHub - m-tranter/timestamp

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0

Challenge Information:

Back End Development and APIs Projects - Timestamp Microservice

I’ve had another look at this and I still can’t pass the tests.
My server is responding with the correct JSON object to calls with “empty date parameter”

Incoming: /api/this-is-not-a-date
{ error: 'Invalid date' }
Incoming: /api
{ unix: 1713724728735, utc: 'Sun, 21 Apr 2024 18:38:48 GMT' }
Incoming: /api
{ unix: 1713724728836, utc: 'Sun, 21 Apr 2024 18:38:48 GMT' }

What you see above is the console log on the server of the incoming request and what is going to be sent back. Please help!

Your code is passing for me. Make sure you submit the root URL and not the one with the /api path.

https://fcc-timestamp-cmum.onrender.com

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