The /now endpoint should have mounted middleware The /now endpoint should return a time that is +/- 20 secs from now

I am on this challenge:

I get this issue:
The /now endpoint should have mounted middleware
The /now endpoint should return a time that is +/- 20 secs from now

This is my code:
Screenshot 2021-04-23 at 10.20.16

This is the output:
https://boilerplate-express.freecodecampdev.repl.co/now

Based on research I believe this is correct but why the issues? Help please.

Please use setTimeOut

var delayInMilliseconds = 1000; //1 second

setTimeout(function() {
  //your code to be executed after 1 second
}, delayInMilliseconds);

I hope this will help you.
2 Likes

So like this:

var delayInMilliseconds = 1000; //1 second

app.get('/now', (req, res, next) => {
     req.time = new Date().toString();
     next()
}, (req, res) => {
setTimeout(function() {
  //your code to be executed after 1 second
    res.json({
      'time': req.time
    })
}, delayInMilliseconds);
});

Please use Date() function in setTimeout function.

Hey @mountian1992 I am still lost on this. :tired_face:

Your code is passing for me. Please make sure you are submitting the correct URL (without /now).

https://boilerplate-express.freecodecampdev.repl.co

1 Like

You’re right thank you :slight_smile:

Thank you again marked as the solution!

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