API time stamp help

Tell us what’s happening:
please some one help me run my code, cause am thinking that its my device time. Which I have adjusted but still not working.

const express = require("express");
const app = express();

// enable CORS (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
// so that your API is remotely testable by FCC
const cors = require("cors");
app.use(cors({ optionSuccessStatus: 200 })); // some legacy browsers choke on 204

// http://expressjs.com/en/starter/static-files.html

// Root endpoint. Display index file
app.get("/", (req, res) => res.sendFile(__dirname + "/views/index.html"));

// Handle returning a timestamp
app.get("/api/timestamp/:date?", (req, res) => {
  // Store our date response. This will default to the current datetime
  let date = new Date();

  // Check if the optional date parameter was provided
  if (req.params.date) {
    // Convert the date parameter to a string
    let unixDate = +req.params.date;

    // Check if the date passed is unix time. If it's not, use the date string provided
    date = isNaN(unixDate) ? new Date(req.params.date) : new Date(unixDate);

    // Check if the date created is valid. Throw an error if it's an invalid date
    if (!(date instanceof Date) || isNaN(date.getTime()))
      return res.json({ error: "Invalid Date" });

  // Return the unix and UTC time
  return res.json({ unix: date.getTime(), utc: date.toUTCString() });

// Create a listener to handle requests
const listener = app.listen(process.env.PORT, () =>
  console.log("Your app is listening on port " + listener.address().port)

Your project link(s)

solution: Glitch
githubLink: Glitch

Your browser information:

User Agent is: Mozilla/5.0 (Android 8.1.0; Mobile; rv:85.0) Gecko/85.0 Firefox/85.0.

Challenge: Timestamp Microservice

Link to the challenge:

Hello there,

I am not sure when you started the project, but the endpoints changed, a few weeks back:

A request to /api/:date? with…

Hope this helps

1 Like

Thanks a lot Sky020.
please help clear my doubt
Few things confused me about extracting value from either html form path or
module.For example:
1.suppose I create html like…

  <article id="my-article">
<p>do some stuff </p>

And at some point in the website I create a link …

  <a href="#my-article">go here for more article </a>

now how do I extract this value of "do some stuff ",on the server using Id or a tag.


// server.js
let express = require("express");
let app = express();
    let article = req.params.my-article

Finally I was thinking that, the route handler path should have the link path so as to link to id.
Please clear my doubt and with other examples helpful thanks.

The reason you want to do this is not clear. Why are you wanting to scrape the HTML? What is your main objective with the data?

Also, if this does not have to do with the Timestamp Microservice project, then you should open a new topic for your questions.