Your project can handle dates that can be successfully parsed by new Date(date_string)

Tell us what’s happening:

Your project link(s)
Your project can handle dates that can be successfully parsed by new Date(date_string) i got this error

githubLink: GitHub - Reshmieb/timestamp at master
solution: http://localhost:60619

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: Timestamp Microservice

Link to the challenge:

Hello there,

As far as I am aware, endpoints are not supposed to end in /:

app.get("/api/timestamp/",

The idea should be to check if a date_string param is included (not undefined).

Hope this helps

i removes that / but again i have got that error

http://localhost:60964/api/timestamp

You understand that I do not have access to your localhost… it is on your machine - not publicly accessible.

app.get("/api/timestamp", (req, res) => {

  res.json({ unix: Date.now(), utc: Date() });

});

app.get("/api/timestamp/:date_string", (req, res) => {

  let dateString = req.params.date_string;

  //A 4 digit number is a valid ISO-8601 for the beginning of that year

  //5 digits or more must be a unix time, until we reach a year 10,000 problem

  if (/\d{5,}/.test(dateString)) {

    const dateInt = parseInt(dateString);

    //Date regards numbers as unix timestamps, strings are processed differently

    res.json({ unix: dateInt, utc: new Date(dateInt).toUTCString() });

  } else {

    let dateObject = new Date(dateString);

    if (dateObject.toString() === "Invalid Date") {

      res.json({ error: "Invalid Date" });

    } else {

      res.json({ unix: dateObject.valueOf(), utc: dateObject.toUTCString() });

    }

  }

});

this is my code
this is the output

{"unix":1451001600000,"utc":"Fri, 25 Dec 2015 00:00:00 GMT"}

Where am i doing mistake

With those corrections, your app passes all the tests for me.

Open up your browser console to help you debug, when you click the submit.

Just for reference, a common pattern used with Express to represent:

app.get('/some-route',...)
app.get('/some-route/:param',...)

Is with:

app.get('/some-route/:param?',...)

Hope this helps

when i pass my peoject link in solution link then Your project can handle dates that can be successfully parsed by new Date(date_string) again i got this error

Please update GitHub with your latest code. Or, better yet, clone your project to a service like Replit or CodeSandbox, or Glitch, then you can share a link to your code.

Can you see the issue here?:

app.get("/api/:timestamp",

but when i remove : then not solve the problem that is again that msg show this is my latest code GitHub - Reshmieb/timestamp at master

When I submit your latest code, it passes all the tests.

Again:

but when i check its working in brower properly but when i submit in solution link i have revived this again

Are you saying there are no errors in the browser console?

yes

,

The console, where you submit the link freecodecamp.org/learn. NOT the console on your app.

on that console i got this error Your project can handle dates that can be successfully parsed by

new Date(date_string)