Still says i failed

My app satisfies all the requirements but still it fails me on every requirement.

// server.js
// where your node app starts
var express = require('express');
var app = express();
var bparser = require('body-parser');
var moment = require('moment');
var dandt = require('date-and-time');
var express = require('express');
var app = express();

app.use(function(req, res, next) {
  console.log(`${req.method} ${req.path} - ${req.ip} `);
app.get('/api/:date?', function(req, res, next) {
  const dd = Date.parse(;
  const d = new Date(;
  const dutc = d.toUTCString()
  const unixnum = Number(;
   if (isNaN(unixnum) === false){
    let unixxnum = new Date(unixnum);
    return res.json({unix:unixnum,utc:unixxnum.toUTCString()});
  }  else if ( === undefined ) {
    let curr = new Date();
    return res.json({ unix: Date.parse(curr), utc: curr.toUTCString() });
  }else if (dutc === 'Invalid Date') {
    return res.json({ error: 'Invalid Date' })
  else {
    return res.json({ unix: dd, utc: dutc })

// init project

// enable CORS (
// so that your API is remotely testable by FCC 
var cors = require('cors');
app.use(cors({ optionsSuccessStatus: 200 }));  // some legacy browsers choke on 204


app.get("/", function(req, res, next) {
  res.sendFile(__dirname + '/views/index.html');


// your first API endpoint... 
app.get("/api/hello", function(req, res, next) {
  res.json({ greeting: 'hello API' });


// listen for requests :)
var listener = app.listen(process.env.PORT, function() {
  console.log('Your app is listening on port ' + listener.address().port);

Your project link(s)


Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0

Challenge: Timestamp Microservice

Link to the challenge:

I can’t get yours to run. When I try to submit it, I see 502 errors. I can’t even get it run on replit. I notice that you have:

var express = require('express');
var app = express();
// ...
var express = require('express');
var app = express();

That might cause problems.

Get an app that runs and we can try to help you.

Move the CORS middleware usage all the way up to the top (right after your other require statements). It has to be mounted before the routes.

It didn’t run at first until I forked it so I’m not sure what is up with that.

1 Like

Thanks guys. I deleted the extra var express = require('express'); var app = express(); and moved my code all the way down and it worked.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.