Can any variable be logged to console, like front end?

I am new to back-end and Glitch. I have search for an answer the following and can’t find a good answer.

How can I log to console just the same way I would do in front-end. Here is an example. This doesn’t log.
Sure would appreciate some insight, thanks.

let reqDateString = req.params.date_string;//store req date
let isoDate = new Date(reqDateString)//ISO format

if(reqDateString > 5){
res.json({“unix”: reqDateString, “utc”: Date.parse(reqDateString)})
console.log(isoDate , " :DATE")
}

If the code with console.log() runs on the server, you’ll find the messages sent to the server’s console log, which can be seen on the Glitch project editor, buttons Tools > Logs

Yes, there is more than one console, haha :slight_smile:

Hey @IrishBrown,

Welcome to the Glitch Forums!

What @mishavee said is absolutely right, and seeing that you’re new to Glitch, here’s how you view the logs that you did in the server-side:

toolbox-logs-console

khalby786, the demonstration you sent is small and I don’t know how to view it. Is there a way to view the it in a larger format?

I have looked a both logs and nothing was logger. Below is the message from the consoles:

Glitch page: https://glitch.com/edit/#!/timestamper-micro

  1. :business_suit_levitating::love_hotel: Your app is listening on port 3000 3:10 PM

2)Welcome to the Glitch console

If you’re following someone else’s instructions make sure you trust them.
If in doubt post a question in our forum https://support.glitch.com

For now, the console and the editor don’t automatically sync. You can
manually run the refresh command and it will force a refresh,
updating the editor with any console-created files.

For more information about this and other technical restrictions,
please see the FAQ: link

There is a bug in the code preventing the console.log from being run. The following condition is false for most date strings, but true for a string such as “6”

if(reqDateString > 5){

Did you want it to check the length of the string? For example,

if(reqDateString.length > 5){

well, backend has more support (i think)

Sorry, @IrishBrown! Here it is:

@khalby786 does backend have more support for these kind of things?

That was a very good point and yes that’s what I was trying to do, but after changing the line still no log. Is there a step-by-step tutorial that you know of?

Question, Does back-end have more control?

That’s mush better. I have checked both console, with not success.

How are you running the server side code? If it is similar to the hello-express example when creating a new project, any console.log in server.js should display in the editor Logs.

@IrishBrown in the Glitch editor, you can look for console.log messages in the “Tools” area under “Logs”. Console is the interactive terminal to your project. The naming can be a little confusing!

@potch Is there 2 consoles?

looking at your last response, I opened a new express project and it look like it logged fine, so I am going start from scratch and rebuild the project. Will let you know the outcome. Appreciate all the help.

2 Likes

Thanks for setting me on the right path! :+1:
For anyone else that may have the same questions, here is what I found out.

  1. for “Glitch console” (console with black screen)
    I need to us node myApp.js or whatever the file name is.
    2)If “nodemon” is installed to constantly watch the your server for changes, then use "nodemon myAppName.js".
  2. Found some end point testing tools such as"Swagger Inspector", “Postman” , “Insomnia”,“API Tester” etc. to check that data passed will behave as expected.

example:
app.get("/api/hello", (req, res) => {
let greet = res.json({greeting: ‘hello API’});
console.log(greet)
});

Using “Swagger Inspector” ,

  1. selecting the “GET” HTTP verb tab

  2. pasting in the “Live App”(from Glitch) or localhost + route
    .i.e https://myglitch-uriproject.glitch.me/api/hello

  3. select “SEND”
    you will get an object that looks like this.

    {
    “greeting”: “hello API”
    }

2 Likes