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

Do you have your project on Glitch by chance?

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

1 Like

myApp.js is not used in your project. Currently, only server.js is running. You can move your code to sever.js.

1 Like

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

The FCC lessons already had a server.js file which tested out your myApp.js code. You never had to modify server.js.

If you put your methods in another file, you have to export from that file and require it in your server.js file. As @RandellDawson 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 @RandellDawson 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

If you look closely, you will find a line similar to the one below in all of the server.js files starting with the Introduction to the Basic Node and Express challenges

var myApp = require('./myApp');

Also, at the bottom of these challenges, you will see some kind of module.exports or exports lines. These are exporting various functions to be used when required by the server.js file.