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

Tell us what’s happening:

Task: Chain Middleware to Create a Time Server

This test isn’t passing:
2. The /now endpoint should return the current time.

I can’t seem to identify the issue. Please help out.

Here’s my code in myApp.js:

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

require(‘dotenv’).config()

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

module.exports = app;

###Your project link(s)

solution: https://3000-freecodecam-boilerplate-q1pro65vgsv.ws-us117.gitpod.io

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

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

Welcome to the forum @batoolahmed218

Try removing the .toString() method.

Happy coding

It still doesn’t work
And the question itself said to you use .toString()

The result is coming as this:
{“time”:“Sun Dec 29 2024 11:15:27 GMT+0000 (Coordinated Universal Time)”}

Should i do this: extract the time and convert it into normal time format?

Does the result time match the system time on your computer?

When I did the module I had to remove the .toString() method and increment the time by several seconds.

Are you doing this on Gitpod or locally?

You could also try using toUTCString instead.

Also, avoid submitting near midnight to avoid issues with daylight savings.

For some reason it works now, even though i didn’t change anything

But thank you!!

1 Like