NodeJS Chain Middleware to Create a Time Server

Hello there :wave:
Kindly assist me, I am stuck at challenge 8 of the Basic Node and Express, where you are supposed to chain a middleware function to create a time server.

I have reviewed similar questions on the forum to no avail; my code still breaks. Here’s the code

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

The code fails both tests
I inspected fcc’s challenge page and it seems that the GET request appends this line to my url:

_api/chain-middleware-time

Here’s my url:
https://boilerplate-express.gitaud.repl.co/now

After editing my code to match the url, the second test passed. Here’s the edited code.

app.get('/now/_api/chain-middleware-time', (req, res, next) => {
  req.time = new Date().toString();
  next();
}, (req, res) => {
  let time_obj = {'time': req.time};
  res.json(time_obj);
});

I have tried almost all variations of code posted on the forum. I will appreciate any form of help, please. Thanks.

try removing now from the URL you submitting. I can’t see any problems in your code. SO the solution link should be https://boilerplate-expres....repl.co/. Forward slash in the end of the link is important.

Thanks, I have just tried that. Sadly the tests failed.

if you still have the code like this app.get('/now/_api/chain-middleware-time' revert it back to app.get('/now'

And then submit the URL path to your project without now

Great, it worked! Thanks.

1 Like