Timestamp Microservice Not Passing?

Tell us what’s happening:
So I uploaded my code on Heroku app and it is live on here: https://timestamp-exercise.herokuapp.com/

And my github source code here: https://github.com/synerjay/timestamp-exercise

But i still cannot pass this page?? It only passed the first story, even though everything seem to work on the microservice.

I did this exercise without cloning the Github repo from FCC. Is this the reason why it’s not passing?

Your code so far

Your browser information:

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

Challenge: Timestamp Microservice

Link to the challenge:

If you open network tab you’ll see that the requests are blocked because of CORS.


Relevant code in FCC boilerplate repo:

Sorry but I dont know what does that mean? I open the network tab and evrything seem to be fine.

Is that related to express? I 'm not using any express in my code btw.

It’s not related to express.

1 Like

Ok. I used the same code and retroifitted the provided Repl.it package and I got the first few stories passed except the last two:

  • 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

const getTimestamp = date => ({ unix: date.getTime(), utc: date.toUTCString() });

app.get("/api/timestamp/:date", function (req, res) {
  const dateString = req.params.date;
  let timestamp;

  if (dateString === undefined || dateString.trim() === "") {
      let currentTime = new Date();
      timestamp = getTimestamp(currentTime);
    } else {
      const date = !isNaN(dateString) ? new Date(parseInt(dateString)) : new Date(dateString);

      if (!isNaN(date.getTime())) {
        timestamp = getTimestamp(date);
      } else {
        timestamp = { error : "Invalid Date" };
  res.writeHead(200, { "Content-Type": "application/json" });

I made the condition for an “undefined” dateString and empty string and yet I cant pass the last two stories . Any insights? Thanks

This is the live link: https://boilerplate-project-timestamp-3.synerjay.repl.co/

Try adding ? after :date

Thank you! It worked! Is that a special feature in request parameters? I only learned /:parameters without the question mark. Would love to learn more about it

Url supports regex (? means 0 or 1 of preceding token, or in simpler words - make optional)

1 Like