'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!
Solution 1:[1]
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().
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Suraj Govind |
