I had this problem too and I just want to reiterate what @santini44 said:
“Code needs to be on myApp.js file and not on server.js”
This solved my problem.
I was working in the server.js file and applying my .use and .get functions to the app object there. However, the fcc tests look at the myApp object when trying to tell if you chained the middleware correctly. So, I started to create a pull request on their repo that altered it to use app._router.stack instead of myApp._router.stack until I saw @santini44 's comment and realized my issue lol !
If anyone is interested, for learning purposes, if you’re using server.js for the exercises - a workaround for this challenge is possible by adding a line near the bottom of the file that copies the app’s router stack into myApp’s router stack…
var port = process.env.PORT || 3000;
myApp._router = { stack: [...app._router.stack] };
bGround.setupBackgroundApp(app, myApp, __dirname).listen(port, function(){
bGround.log('Node is listening on port '+ port + '...')
});
… this is because the fcc-express-bground uses the stack object in myApp to see if the “/now” routes stack is the proper length of 2, meaning the middleware is mounted on the .get() route
try {
//myApp.use(enableCORS);
app.use('/', myApp);
var stack = (myApp._router && myApp._router.stack) || [];
var layers = stack.map((l) => l.name);
.....
// check if /now route has a middleware before the handler
var nowRoute = stack.filter((l) => {
if (l.route) {
return l.route.path === '/now';
}
return false;
});
if (nowRoute.length > 0) {
nowRoute = nowRoute[0];
globals.nowRouteStackLength = nowRoute.route.stack.length;
}
It’s also possible to get at the stack with myApp.parent._router.stack , but I didn’t spend too much more time on this after I realized where I went wrong
So, long story short… when the file says “PLEASE DO NOT EDIT THIS FILE” you should probably not edit it
I had an issue with the response falling within the 20 second ± window. I manually adjusted my computer clock to match the output that was displayed on /now and passed the challenge.