TimeStamp Challenge - Help

// server.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({optionSuccessStatus: 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');
});


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



app.get('/dateValues/:dateVal', function(req,res){

var dateVal = req.params.dateVal;

var dateFormatingOptions = {
year:'numeric',
month:'long',
day:'numeric'
};
if(isNaN(dateVal)){
var naturalDate = new Date(dateVal *1000)
naturalDate = naturalDate.tolocaleDatestring("en-us", dateFormatingOptions);
var unixDate = new Date(dateVal).getTime()/1000;
}
else
{
var unixdate=dateVal;
naturalDate = naturalDate.tolocaleDatestring("en-us", dateFormatingOptions);
}

res.json({unix: unixDate, natural: naturalDate});
});



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

Please can someone help me to see what I’ve done wrong? It keeps saying that it cannot GET /api/timestamp.

Thanks

This is the .json file.

{
  "name": "fcc-api-projects-boilerplate",
  "version": "0.0.1",
  "description": "An FCC Backend Challenge",
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^4.16.4",
    "cors": "^2.8.5"
  },
  "engines": {
    "node": "4.4.5"
  },
  "repository": {
    "type": "git",
    "url": "https://githost.com/camper/repo.git"
  },
  "keywords": [
    "node",
    "hyperdev",
    "express",
    "freecodecamp"
  ],
  "license": "MIT"
}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

Do you have this route in your code? I don’t see it.

I’ve tried that but I keep getting the wrong results. Where does it need to be?

Thank you for pointing that out! I’ve now solved this!

Actually it isn’t working! Where am I meant to put it?

Try after this:

app.use(express.static('public'));

That’s already in the code, and its still not working unfortunately.

Cannot GET /api/timestamp/2015-12-25

This is the error message.

Put after that.

app.get("/api/timestamp", function (req, res) {
  res.send('hello from timestamp');
});

Yes that works fine.

Although the output for the original exercise is not working.