Chain Middleware to Create a Time Server - problem

Tell us what’s happening:
There’s nothing wrong with code:

> app.get("/now", (req, res, next) => {
  req.time = new Date().toTimeString();;
  next();
}, (req, res) => {
  res.json({ time: req.time });
});

Your project link(s)

solution: https://replit.com/@joexhsn/boilerplate-express

Your browser information:

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

Challenge: Chain Middleware to Create a Time Server

Link to the challenge:

Hi @ Joe_Hsn

From the instructions:

You can use new Date().toString()

That’s what the tests are looking for.

should be toString()

I TRIED THE SAME PROBLEM.
Ah, and , many thanks for your reply :heart:.

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

I TRIED THE SAME PROBLEM.
Ah, and , many thanks for your reply :heart:

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

your code seems correct, there might be issue of two semicolons, remove one

1 Like

i did, but still the same problem

Well, that’s weird - I just tried your code, and it passes the tests for me.

You did stop/start the server, didn’t you?

1 Like

i did, I’ll try to clone the starter project and submit again. and many THANKS :heart: :grin:

It didn’t work too :joy: :smiling_face_with_tear:

Baffled.

I’m wondering whether you’ve maybe accidentally deleted something that you need.

Here’s the link to my replit edit: wrong link- removed

I’ve commented out everything except your code for this challenge, as well as the code for the preceding ones.
And I’ve checked that it passes the timestamp test.

Have a look at it - see if you can spot anything missing from your code.

Oops - sorry, about that! This should work - boilerplate-express - Replit

1 Like

I’M DONE :rage: :face_with_symbols_over_mouth::sob: :woozy_face: :joy: :joy:



The wrong thing is me?

I’ve been looking through forum posts related to this challenge.

Could this be a timing issue?
I mean, could there be more than 20 seconds between your code running and the test checking the timestamp?

If so, this thread might be interesting.

Failing that, you might just have to move on.
You don’t need this code for the remaining challenges (and the certificates only depend on the projects, not these challenges).

1 Like

thank you so so so much, even it won’t work :heart:

I’m really sorry we didn’t manage to find a solution for you.

But the important thing is that your code was definitely OK - you’ve got this!

Good luck for the rest of the challenges!

1 Like

I had the same problem. I resolved this by changing the new Date().toString() to a hard-coded date. I added estimated seconds before clicking the submit. Luckily, I passed!

1 Like

I had the same problem…
failed at passing

  • The /now endpoint should return the current time.

For the guys who will check this post. I didn’t change anything, just tried to submit link on other computer, it worked. (most probably other browser will work too)

I think this could be the testing method issue.
I mean, which ‘time’ is it looking for? In what format? region?

When I hard coded it, it passes.
But when I do it properly, it cannot detect the current time.