Tell us what’s happening:
No matter what I try I cant get the webpage to load. I have tried to rewrite the code, watch YouTube videos and I cant find anything.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Challenge Information:
Back End Development and APIs Projects - Timestamp Microservice
// index.js
// where your node app starts
// init project
var express = require('express');
var app = express();
// enable CORS (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
// so that your API is remotely testable by FCC
var cors = require('cors');
app.use(cors({optionsSuccessStatus: 200})); // some legacy browsers choke on 204
// http://expressjs.com/en/starter/static-files.html
app.use(express.static('public'));
// http://expressjs.com/en/starter/basic-routing.html
app.get("/", function (req, res) {
res.sendFile(__dirname + '/views/index.html');
});
const isInvalidDate = (date) => date.toUTCString() === "Invalid Date";
// your first API endpoint...
app.get("/api/hello", function (req, res) {
let date = new Date(req.params.date);
if (isInvalidDate(date)){
date = new Date(+req.params.date);
};
if(isInvalidDate(date)){
res.json({error: "Invalid Date"});
return;
};
res.json({
unix: date.getTime(),
utc: date.toUTCString()
});
});
app.get("/api", (req, res) => {
res.json({
unix: new Date().getTime(),
utc: new Date().toUTCString()
});
});
// Listen on port set in environment variable or default to 3000
var listener = app.listen(process.env.PORT || 3000, function () {
console.log('Your app is listening on port ' + listener.address().port);
});