Node Express - Chain Middleware to Create a Time Server

Tell us what’s happening:
All tests fails:

The /now endpoint should have mounted middleware
The endpoint should return the current time.

My source:

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

Your project link(s)

boilerplate-express - Replit

** got help from here: **

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0

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

Link to the challenge:

This could be your problem.

same errors if i use:

res.send({ "time": reg.time });

Yes, you will still fail, because the code is still incorrect.
What is reg.time?

at the console this gives me no output:

    req.time = new Date().toString();
    cosole.log('time=' + reg.time);

reg.time is incorrect code. So is cosole.log, but that’s another thing.

1 Like

same errors with this updates and still no output at console with console.log :

app.get(
  "/now",
  (req, res, next) => {
    let timeStr = new Date().toString();
    req.string = timeStr;
    console.log('timeStr=' + timeStr); //  no output. idk why
    next();
  },
  (req, res) => {
    res.send({ "time": req.string });
  }
);

I just forked your repl and it passes for me. I don’t know why it’s not passing for you, sorry.
When I visit your ‘/now’ endpoint, I get an error ‘reg is not defined’.
Perhaps if you exit replit and then log back in again, it will have updated to your current code?

I just forked your replit and ran it. I get no errors, see the result of the console.log, and all the tests pass.

Make sure you stop and restart the server before submitting the url again. Also, what is the exact url you are submitting?

1 Like
  1. i always jump to
    boilerplate-express - Replit
    in my web-browser.
  2. then i copy the url from the top right https://boilerplate-express.sl5net.repl.co
  3. copy it into the back-end-development-and-apis/basic-node-and-express/chain-middleware-to-create-a-time-server
    and then…

but now it works :smile: :smile: :smile: :smile:
what i did. i was at kitchen was drinking something.

thats very strange.

is there a reason for latency? at the moment i also could use mobile-fon conection. something to do whit it.

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