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

Tell us what’s happening:
Describe your issue in detail here.
I have no idea why this isn’t working; please assist me.

My code:

app.get(‘/now’,
(rq, rs, next) => {

      const newtime = new Date().toString();
      rq.time = newtime;
      next();
      
    },
    (rq, rs) => {

      rs.json({time: rq.time});
      
    });

Your project link(s)

solution: boilerplate-express - Replit

Your browser information:

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

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

Link to the challenge:

The /now route could be simplified by using a single middleware function instead of two.

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

Your code is passing for me.

Make sure your PC’s clock is synced correctly. You can also try running it locally.

It still did not work

I think so.
I wrote a code to check the current time; it’s not synced and incorrect.
Any idea how to change or update my current time on Replit?
Anyway, let me try running it locally. Thanks.

Are you talking about your PCs time? Try to sync it.

I tink your replit is not on:its not showing eniting
sorry now is on…

 console.log('Middleware for /now endpoint');
        

try to see what will give you back:
ok

It’s still not working.

Thank you.
I synced it; it is still not working.

Try it locally and see if that helps.

Yeah, it worked locally.
Thanks a million!

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