Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading