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