Testing API Project with console log

app.get('/api/timestamp/:date_string', function(req,res) {
  let paramDate = req.params.date_string; // get :date_string

I’m trying to log out my var values to the console for testing.

Can anyone tell me how to do this in Glitch?
I just keep getting the same log message, but no console.log() messages:
Your app is listening on port 3000


Are you making a call to this endpoint? Something like <base url>/api/timestamp/2012-12-31

In the Timestamp Microservice project, the url in your browser’s address bar is given as https://curse-arrow.glitch.me/api/timestamp/2015-12-25

Yes, I see what you mean.

I’ve used Change URL to /api/timestamp/2015-12-25

and I get “Cannot GET /api/timestamp/2015-12-25”

In Glitch, are you using tools --> logs?

Yes I am using Tools - Logs

I’ve tried

app.get("/", function(req, res) {

I can see the contents of the index.html page in the preview window. But no console output.
The console messages like “Your app is listening on port 3000” are coming from server.js (provided by FCC)

Can I see your whole server.js file? I mean, can you post it as a code block?

// 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

// 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'});

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

In what file is the following method:

app.get('/api/timestamp/:date_string', function(req,res) {
  let paramDate = req.params.date_string; // get :date_string


Following the same pattern as the API lessons,
I created a file called myApp.js

So all my functions are in myApp.js next to server.js

Try putting the method I just mentioned directly into your server.js file and see what happens.

1 Like

I’ve completely missed something here then.
I thought I had to create a myApp.js file as in the FCC lessons.

If you put your methods in another file, you have to export from that file and require it in your server.js file. As @camperextraordinaire mentioned, the lessons were set up differently. For this project, you can just use the server.js file for your back-end logic.

Thank you @camperextraordinaire and @willjw3

I was disappointed I was failing at the first hurdle.
I had gone through server.js for the FCC lessons and hadn’t found a reference to myApp.js so I figured it wasn’t needed.

Hang in there!
It takes a while to get used to these full-stack projects.

1 Like