borel
February 24, 2023, 8:17am
1
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
lasjorg
February 24, 2023, 8:42pm
3
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.
borel
February 25, 2023, 6:50pm
4
yes i had done it with json but the code is not working
lasjorg
February 25, 2023, 6:52pm
5
Post your latest code so we can see it.
borel
February 25, 2023, 6:53pm
6
// 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};
});
lasjorg
February 25, 2023, 6:54pm
7
Same mistake, res.json()
is a method.
res.json({key:value});
borel
February 25, 2023, 7:00pm
8
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});
});