Back End Development and APIs Projects - Timestamp Microservice

Tell us what’s happening:

[SPOILER] -
This is the last remaining problem I am facing.

// CODE
let responseObject = {};

app.get(‘/api’, (req, res) => {
responseObject[‘unix’] = new Date().getTime();
responseObject[‘utc’] = new Date().toUTCString();

res.json(responseObject);
});

app.get(‘/api/:date’, (req, res) => {
let date = req.params.date;
console.log(date);

if(date.includes(‘-’)){
responseObject[‘unix’] = new Date(date).getTime();
responseObject[‘utc’] = new Date(date).toUTCString();
console.log(responseObject);
} else {
responseObject[‘unix’] = Number(date);
responseObject[‘utc’] = new Date(Number(date)).toUTCString();
console.log(responseObject);
}

if(!responseObject[‘unix’] || !responseObject[‘utc’]) {
res.json({error: ‘Invalid Date’});
}

res.json(responseObject);

});

Your project link(s)

solution: boilerplate-project-timestamp (1) - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Challenge: Back End Development and APIs Projects - Timestamp Microservice

Link to the challenge:

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