Winston Logger - NodeJs Debug console logs not showing in VSCode - node.js

I'm using VSCode debugger and winston logger for NodeJS, but can't see output from application unless I specify external terminal like this:
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/server.js",
"console": "externalTerminal"
}
]
Is there way to see that output in output window, like when i start code using CodeRunner plugin?

When using a logger that outputs to
process.stdout.write
you can use
"outputCapture": "std" in the launch config to also capture that.

Related

Node Debugging in WSL

I am using Windows 10 WSL in VSCode.
I have the extensions remote development, WSL, I have node installed, nvm as well.
When in work in a remote WSL and try to debug I don't have the Node option at all.
When I run the file I get:
No debugger available, can not send 'variables'
My launch.json is as follows:
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]
}```
Can someone please help me fix it by adding Node.js option so I can properly debug?
Thanks a lot in advance!
Did you found the solution eventually?
I add similar issue, I could get things working only by specifying the node binary path explicitly.
get your node binary path by issuing:
which node
then add it to your launch.json config:
{
"name": "Launch Program",
"program": "${workspaceFolder}/helloworld.js",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node",
"runtimeExecutable": "/home/user01/.nvm/versions/node/v14.18.0/bin/node"
},
Still there is something is wrong going on, even though I simply the setup tutorial:
https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl

only shown legacy and preview options for debugging node.js

I am currently trying to start a node.js project is VSCode, and I want to set up the debugger with a launch.json file. I understand the way to do this is to go to run -> add configuration, but when I do so, there is no option to select the "Node.js" environment specifically (there is Node.js (legacy) and Node.js (preview) as shown in the screenshot attached). I'm currently on v10.15.1 (in another project I am able to debug in a 'pure' Node.js environment, where the type property of configurations in launch.json is set as "node") - is this supposed to cause issues?
this stackoverflow post can help you.
In summary, legacy and preview means old and new nodejs debugger in vscode, respectively.
The following json snippets show the difference between launch.json files using the two debuggers, and only the type field differs.
// node-preview
"configurations": [
{
"type": "pwa-node", //differs
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]
//node-legacy
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]

VSCode Nodejs debugger does not save changes?

I am just starting to learn using the Nodejs debugger. It has been really helpful already but I spent a a lot of time changing a js file I was debugging but I did not know that the changes I made were not being implement right away.
Is this an expected behavior? Can I set the debugger up so that it restarts on each save and notices the new changes?
Edit 1 :
Here is my debuf config:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\app.js"
}
]
}
Normally, after every save, you have to restart your node program to see the changes. I'm sure there are other programs but one I use exclusively (I never use node alone) is nodemon. It's globally installed npm package program. Here is sample config for vs code debugger:
{
"type": "node",
"request": "launch",
"name": "Launch app - nodemon",
"runtimeExecutable": "nodemon",
"runtimeArgs": [
"--inspect=9250"
],
"program": "${workspaceRoot}/api/app",
"cwd": "${workspaceRoot}/api",
"autoAttachChildProcesses": true,
"restart": true
},
nodemon will monitor all the files and restart node every time it detects changes.
Add runtimeArgs to change debugger port.

grunt.log.writeln is not displayed in vs code debug console

I am trying to debug gruntfile.js in VS Code. My launch.json looks like this:
{
"name: Grunt",
"type": "node",
"request": "launch",
"program": "/usr/local/bin/grunt",
"args": ["build_script"],
"cwd": "${workspaceRoot}",
"stopOnEntry": false,
"console": "internalConsole"
}
It works and I can debug it using breakpoints, etc., but the issue is that all outputs which are done with grunt.log.writeln(..), grunt.fail.warn(..) are not displayed in debug console.
How to make grunt to use the debug console for grunt.log?
Thanks

VSCode Debugger pauses unexpectedly in node modules files

While running my nodejs server code through the VSCode Debugger it pauses weirdly in multiple node module library files. Then I just have to hit play button like a hundred times to finally run the whole code. This is so annoying. I have no idea how to fix it. I even tried skipping node module files and folder in launch.json file but it just doesn't seem to work. Below is my launch.json file.
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}",
"cwd": "${workspaceRoot}",
"skipFiles": [
"${workspaceRoot}/node_modules/**/*.js",
"<node_internals>/**/*.js"
]
},
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"address": "localhost",
"port": 5858
}
]
}
uncheck them and it will work smoothly

Resources