Back end development: Chain Middleware to Create a Time Server

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

tried solutions here and here with the same result.

my guess was that there’s a time zone difference so I tried: ETC/GMT+1, -1, +2, -2 … which didn’t do the trick.

We need to see your code. Preferably a live version on Replit.

let express = require('express');
let app = express();

  (req, res, next) => {
    req.time = new Date().toString();
  (req, res) => {
      time: req.time

Your code is passing for me. Although I did see it fail one time with a timeout as well (from running it on Replit).

Where are you running the code from?

I’ve used: Create a new Repl - Replit
VPN didn’t help :upside_down_face:

Not sure why it is failing for you. Maybe try it locally.

it works locally. Thanks!
(hard code the date as string also works if your’e fast :wink:)

I hard-coded the date as string and I passed. I think I got lucky after I have estimated +20 seconds before I click the pass. Thanks for this tip!

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