I have an express.js app.
Whenever I try to debug/run it in vscode, it just runs through and exists. How do I keep this process alive just like it normally does? Or is something wrong with my config?
No errors whatsoever are thrown.
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "www",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"www"
],
"address": "localhost",
"port": 5000,
"stopOnEntry": false,
"cwd": "${workspaceRoot}",
"env": {
...
}
}
]
My npm-script looks like this:
flow-node www/index.js
I want to debug/run this script from vscode since I have a lot of env-variables and, obviously, for debug-reasons.
You may just need to specify the program attribute of the launch.json config.
program - executable or file to run when launching the debugger
https://code.visualstudio.com/docs/editor/debugging#_launchjson-attributes
Related
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.
When debugging in vscode I'd like to make some "blackboxing" and do not enter into code I didn't write. How can I do this?
In your launch or attach debug task you can enter a
"skipfiles"
option which is
"An array of file or folder names, or path globs, to skip when debugging."
For example, from skipping node internals during debugging
"skipFiles": [
"${workspaceFolder}/node_modules/**/*.js",
"${workspaceFolder}/yourLibToSkip/**/*.js"
]
Also, there is a "magic reference" to the built-in core node modules you can use:
"skipFiles": [
"<node_internals>/**/*.js"
]
I was confused on where to put the setting, so just in case, if you want to skip both node_modules deps and node_internals files, your .vscode/launch.json file should look something like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Tests",
"type": "node",
"request": "launch",
...
"skipFiles": ["<node_internals>/**", "${workspaceFolder}/node_modules/**/*.js"]
}
]
}
Only this worked for me.
"debug.javascript.terminalOptions": {
"skipFiles": [
"<node_internals>/**"
]
}
Just to amplify on Mauro Aguilar's correct answer, here are the complete contents of my launch.json file. Note that I am debugging a ReactJS app (circa 2021) with VS Code 1.60.2 on Windows 10 using Chrome v.94. If you're using a Linux machine or a Mac, YMMV.
{
// 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": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}",
"skipFiles": ["<node_internals>/**/*.js", "${workspaceFolder}/node_modules/**/*.js"]
},
]
}
this is my launch.json file (it works for me):
{
"version": "0.2.0",
"configurations": [
{
"type": "edge",
"request": "launch",
"name": "Launch Edge against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}",
"skipFiles": [
"${workspaceFolder}/node_modules/**/*.js"
]
}
]
}
For flutter apps, add to your user settings the following:
"dart.debugExternalLibraries": false,
"dart.debugSdkLibraries": false,
For some reason, I've needed to add both types of skip file entries,
"skipFiles": [
"${workspaceFolder}/node_modules/**/*.js",
"<node_internals>/**"
],
This seems to have resolved the issue.
"dart.debugExternalLibraries": false,
"dart.debugSdkLibraries": false,
If I add this, the debug stop after a few steps into
For Typescript built with Webpack, I had to put the exclusions in launch.json - putting them in settings.json/terminalOptions had no effect.
Also, I had to exclude the pattern of the generated files, not the source files. In my case it looks like:
"skipFiles": [
"<node_internals>/**",
"**/vendors-*",
],
I have a (Botpress Framework v.10.51.1) bot and I have a botpress-module installed and linked to the bot, I wanted to debug the code in the botpress-module using vscode debugger,
I added the following to my vs-code launch.json and started my bot with the command npm start --debug
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"cwd": "${workspaceRoot}",
"port": 5859,
"program": "${workspaceRoot}/node_modules/botpress/bin/botpress",
"runtimeExecutable": "node",
"runtimeArgs": [
"--debug"
],
"args": [ "start" ],
"stopOnEntry": false
}
It's still not launching the debugger in vscode , What am i missing ? How do I do this?
It's hard to tell why it doesn't work on Botpress 10...
However, if you clone the latest version of the Botpress repo (12.0.1), you'll find the following launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"runtimeVersion": "10.11.0",
"request": "launch",
"name": "Debug App",
"program": "${workspaceFolder}/out/bp/index.js",
"cwd": "${workspaceFolder}",
"args": ["start"],
"protocol": "auto",
"env": {
"BP_MODULES_PATH": "${workspaceFolder}/modules:${workspaceFolder}/internal-modules",
"NODE_PATH": "${workspaceFolder}/out/bp",
"DEBUG": "bp:*"
},
"smartStep": true,
"outFiles": [
"${workspaceFolder}/out",
"${workspaceFolder}/modules/*/dist",
"${workspaceFolder}/private-modules/*/dist",
"!${workspaceFolder}/**/node_modules"
],
"console": "integratedTerminal",
"sourceMaps": true,
"autoAttachChildProcesses": true
}
]
}
Which works great for debugging the backend part of modules. It only requires you to start debugging with vscode using the "F5" key or by going to "Debug > Start Debugging".
I hope this information helps.
#Mahesh VSCode allows you to easily debug Botpress. I have created a tutorial that can help understand what are the different ways you can debug a problem in Botpress.
We will use VSCode debugging and Botpress logging capability to find and resolve bugs in our bot
Let us try to debug this, by adding 3 additional statements debugger, console.log & bp.logger.info in our ValidateEmailSignature custom action.
Please checkout below tutorials for more information
https://youtu.be/89dFPVbXxCw
https://aabingunz.com/debugging-in-botpress/
I have gone through plethora of articles online ,I have tried every possible way given online for this but nothing has worked for me till now.
I have reinstalled node,vs code,npm all again but nothing is working.
I am using ->
VSCode Version: 1.27.2
OS Version: Windows 10 Pro 64bit OS,x64-based processor
Node version: v8.11.3
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": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/dist/LeonardoGrader.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/dist/**/*.js"]
}
]
}
Any help will be appreciated.Thanks in advance.
That output means that your program ran to completion without ever stopping in the debugger. Either set some breakpoints or change the stopOnEntry option to true to stop the program on the first line of code.
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