Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

432
Views
Can't use console.log inside app.get method, but works outside of it

So I am having a problem I can't fix. Every time I type console inside my app.get method I can't log anything. I can't call any other methods related to console either. I've tried reinstalling nodejs, deleting node modules, it doesn't matter if I use a different IDE (VS Code, WebStorm, Brackets) I always get this odd error where it just shows this: picture of broken console

I don't know how to fix this and I'm confused about what I did to even break the console to no longer have access to any of its methods. Any help would be appreciated!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Please, no pictures of code. Always copy/paste and put it a code block.

As for your issue, you're trying to add a console log to the payload you're sending in the response. Where would this console log be output, when it has already been sent in the response, outside of your app?

If you want to log inside app.get, do this:

app.get('url', (req, res) => {
  console.log('hello world')
  res.status(200).send("hello");
});

You can also add the json instead, but you should use EITHER res.send() or res.json().

See here for the difference:

Difference between res.send and res.json in Express.js

about 4 years ago · Juan Pablo Isaza Report

0

By going through the image, the reason why console.log() is not working is that you're using it inside a json object.

When you do res.status(200).json() you pass the response json as a parameter.

The json can only contain valid javascript keys and values. It cannot contain function executions (as functions cannot be serialised)

wooooooo's answer is correct. Use console.log() or any other function outside res.json().

Know more about res.json()

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!