Hello there
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.