Chain Middleware to Create a Time Server - Not again!

Tell us what’s happening:
The dreaded " Chain Middleware to Create a Time Server" page! I’ve gone through a lot of the forum posts on this and most of the trouble seems to be with getting the time right and having to alter the computers time to get it to work but… I can’t even get the first test to pass - “The /now endpoint should have mounted middleware”

*I am on Mac OSX 10.14.5
*Using Chrome
*My time was an hour ahead (In the UK) but even after changing the time back an hour it didn’t change anything.

FWIW, I have copied other answers (which passed other users) in without any luck.

I don’t know if the other code from previous lessons affects it in any way but I’ve put this code first in the editor.

I’ve also tried commenting out the other code and trying it with and it doesn’t make a difference.

Your code so far

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

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

Your browser information:

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

Challenge: Chain Middleware to Create a Time Server

Link to the challenge:

use moment to change the time zone as you like
https://momentjs.com/timezone/

1 Like

Thanks, weirdly enough, it worked even though I don’t think it should have:

var express = require(‘express’);
var app = express();
var moment = require(‘moment-timezone’);
var a;
var b;

moment.tz.setDefault(“America/New_York”);

app.get(’/now’, function(req, res, next) {
req.time = new Date().toString();
next();
}, function(req, res) {
a = moment.tz(req.time, “Asia/Taipei”);
b = req.time;
return res.json({‘time’: a});
});

Honestly, I was just experimenting by looking at the different formatting and this seemed to pass.

Weird because it still shows as an hour earlier than where I am (and obviously different from Taipei / New York) so I’m guessing it has something to do with the different formatting.

Either way, I’m just happy to be through the gates!

1 Like