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

Tell us what’s happening:
I write my code like this

function timeMiddleware(req, res, next) {
req.time = new Date().toString();
next();
}

app.get(‘/now’, timeMiddleware, function(req, res) {
res.json({ time: req.time });
});

but i could not pass the
Failed:The /now endpoint should have mounted middleware

Your project link(s)

solution: boilerplate-express - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36

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

Link to the challenge:

Well, I believe your code looks good, but why is it all in the server.js file instead of the myApp.js file?

At the start of this course, it instructed you to add your code to the myApp.js file. In fact, at the bottom of the server.js file it says the following:

image

Now technically you should be able to run middleware in the server.js file, but perhaps the tests are specifically looking in the myApps.js file for this test, although seems your previous tests passed just fine.

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