Basic Node and Express - Chain Middleware to Create a Time Server

Yeah guys, is not the code at all, is the time of the Date object and the time of you machine wich have ± 21 seconds of difference

For me, my PC had like 40 SECONDS of difference, so, its was hard to set.

Yes. Sync your PC’s clock and it solves the problem. Google for your local time.

Hello !
Here is what I did to fix the problem:

app.get('/now', (req, res, next)=>{
  req.time = new Date( - 30000).toString();
}, (req, res)=>{
  res.json({time: req.time});

Make sure to subtract(or add) the appropriate number(milliseconds) so that the time on your PC is close enough to pass the test.


you have to change your computer time…

i used google to check the time use keyword date now
and match it to your computer .


the test did not pass

My solution was to open check the time in the console on the freeCodeCamp challenge page , just type Date()

and then add the string on your project like this

res.json( { time: 'Sun, 03 May 2020 21:14:16 GMT' } )

just use your own time

Thank you so much man. You’re the best!!

If you are using, chances are that you are having trouble passing this challenge, because you are ± 20 seconds off.
your code looks like this:

app.get(’/now’,(req,res,next)=> {
req.time = new Date().toString();
}, (req,res)=> {

That should work, but it doesn’t because your PC timezone is not the same as your browser.
The solutions is to set your timezone and time to automatic in your PC settings.

That should solve it all.

1 Like

you are simply amazing. thank you very much.

Please pay attention where you are writing. if you are using with given boilerplate -express code then you should write into method to myApp.js file.