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

here is my code i do anything but is not working

let express = require(‘express’);
let app = express();

app.get(‘/now’, function(req, res, next) {
req.time = new Date() .toString() ;
next()
},
function(req,res) {
res.send = {“time”: req.time};
});

//
What do I need to do to return time between ±20 seconds

please i need your help

res.send() is a method you need to call it.

object.method(args);

If you do not respond (with a method call, or a return) the server will just hang on the request.


Just as an aside, when the challenge asks for JSON I would suggest using the res.json() method. It will pass with res.send() sending JSON but it is better to use the json method when sending JSON.

yes i had done it with json but the code is not working

Post your latest code so we can see it.

// you see this my code

let express = require(‘express’);
let app = express();

app.get(“/now”, function(req, res, next) {
req.time = new Date().toString();
next()
},
function(req,res) {
res.json = {“time”: req.time};
});

Same mistake, res.json() is a method.

res.json({key:value});

thanks but it still doesn’t work

let express = require(‘express’);
let app = express();

app.get(“/now”, function(req, res, next) {
req.time = new Date().toString();
next()
},
function(req,res) {
res.json({“time”: req.time});
});

its working thank you :grinning: