Tell us what’s happening:
I am having diffculty identifying where /how this middleware is supposed to be “mounted” to the "/now? endpoint. I have the response working right but my function is not mounted. Please could someone help me out? Here’s my code.
var express = require(‘express’);
var app = express();
function middleware(req, res, next){
req.time = new Date().toString();
console.log(req.method + " " + req.path + " " + “-” + " " + req.ip);
next();
};
app.use(middleware)
app.get(“/now”, middleware, (req, res) => {
res.json({time: req.time})
})
Your project link(s)
solution: boilerplate-express2 - 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/107.0.0.0 Safari/537.36
Challenge: Basic Node and Express - Chain Middleware to Create a Time Server
Link to the challenge: