Tell us what’s happening:
Tests of “Timestamp Microservice” excercise doesn’t works correctly, test get never passed.
Commentary:
I tried to pass the test with the next code, using replit:
app.get('/api/:date?', (req, res) => {
const time = !isNaN(Number(req.params.date)) ? parseInt(req.params.date) : (req.params.date || Date.now());
console.log(req.params.date, time);
const date = new Date(time);
const result = {};
console.log(date);
if(isNaN(date))
result.error = "Invalid Date";
else
result.unix = parseInt(date.getTime()), result.utc = date.toUTCString();
console.log(result);
res.json(result);
});
But doesn’t works, so i tried the provided app exampled and it doesn’t pass either (with the same error).
I also tried: freecodecamp-back-end-development-and-apis/server.js at main · mariodmpereira/freecodecamp-back-end-development-and-apis (github.com), but that code doesn’t pass either… (same error…)
Test output:
// running tests
You should provide your own project, not the example URL.
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
// tests completed
Your project link(s)
solution: https://timestamp-microservice.freecodecamp.rocks
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.27
Challenge: Back End Development and APIs Projects - Timestamp Microservice
Link to the challenge: