I'm trying to debug a heroku nodejs from vscode
My launch.json
{
"type": "node",
"request": "attach",
"name": "Heroku",
"address": "localhost",
"port": 9229,
"protocol": "inspector",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
My ProcFile
web: node --inspect-brk=9229 ./server.js
Already did a git push with of the ProcFile, then I run
heroku ps:forward 9229
Then I run de debug "Heroku" in VSCode, but it doesn't seem to be connecting, after some time I got the message
"Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target:socket hang up"
But if I click on stop before that message shows the forwarding process in the terminal stops, so not sure if it's connecting or not, or I still need to configure something else
Thanks
In all the tutorials using http triggers, the .vscode launch file has this:
{
"name": "Attach to Javascript Functions",
"type": "node",
"request": "attach",
"port": 9229,
"preLaunchTask": "func: host start"
}
So now I've added a second function in the same function app. It uses a service bug trigger. I'd like to test it locally before deploying to azure. So now how do I extend the launch configurations? I can copy the block and change the name but how will the debugger know which func to kick off?
Thanks!
No modification required actually. The inspector(debugger) is not attached to any specific function, instead, it is enabled for the function node worker, which loads all functions we create.
When we debug we could see
Starting language worker process:node --inspect=9229
"C:\Users\UserName\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\node\dist/src/nodejsWorker.js" --host ...
node process with Id=2276 started
Generating 2 job function(s)
Debugger listening on ws://127.0.0.1:9229/0c8f2c9a-80cd-4ab6-914e-1c65d29f43c6
Latest VSCode version 1.61.0 breakpoint unbound.
my config
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"preLaunchTask": "npm: start",
"sourceMaps": true,
"smartStep": true,
"port": 58167,
"protocol": "inspector",
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
}
}
I'm testing out the VS Code node debugger, but I'm not able to find any node processes when trying to attach to a running process.
This is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
}
]
}
the contents of my package.json file:
"scripts": {
"start": "node --inspect=0.0.0.0:9229 ./bin/www"
}
After I start up the process using 'npm start', I press 'start debug' and the list of node processes is:
1 sssd_pam
1 sssd_nss
1 sssd_be
Looks like this and none of these are the server I just launched.
This list persists even after I take down the node server.
Why am I not able to see any of my running node processes in the VSCode process attach?
P.s. I'm closely following this tutorial on debugging Node.js with VS Code.
Are you running the NodeJS in debug mode inside npm start? You need to use the --inspect flag. Without this flag, the NodeJS interpreter won't open the debug port to the VSCode to attach to.
Refer to: https://nodejs.org/en/docs/guides/debugging-getting-started/
Another option is to attach using a port definition. I usually do something like this in the launch.json:
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229,
"restart": true,
"sourceMaps": true,
"protocol": "inspector"
}
Then I start the NodeJS process as: node --inspect=0.0.0.0:9229 start.js
I was trying to launch the program from the debug console in VS Code but got the error on cannot connect to runtime process timeout after 10000 ms
launch.json
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"protocol": "inspector",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
},
{
"type": "node",
"request": "attach",
"protocol": "inspector",
"name": "Attach",
"port": 9229
},
{
"type": "node",
"request": "launch",
"port":9230,
"name": "Launch Program",
"program": "${workspaceFolder}\\bin\\www"
}
]
}
I am trying to debug with VS Code but got hit by the error as below. Am I configuring my launch.json correctly ?
A "launch"-type configuration doesn't need to specify a port. When you set the port parameter, it assumes that your launch config will include the --inspect parameter with that port.
If you have to specify the exact port for some reason, then you can include the --inspect parameter like:
{
"type": "node",
"request": "launch",
"port":9230,
"runtimeArgs": ["--inspect=9230"],
"name": "Launch Program",
"program": "${workspaceFolder}\\bin\\www"
}
But I recommend just removing "port" from your launch config.
I'm using nodemon and babel to start visual studio code and found that you need to make sure you have a configuration in package.json and launch.json that are compatible with visual studio code.
Really, that means that you need to find a configuration that allows you to launch your regular configuration from powershell as well as gitbash in windows. Here's what I came up with:
In package.json
"scripts": {
"start": "nodemon --inspect --exec babel-node -- index.js",
},
In launch.json
{
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"name": "Launch via Babel (works)",
"cwd": "${workspaceRoot}",
"port": 9229,
"program": "",
"runtimeExecutable": "npm",
"console": "integratedTerminal",
"runtimeArgs": [
"start"
]
}
]
}
When node starts you should see something like:
PS F:\noise\bookworm-api> cd 'F:\noise\bookworm-api'; & 'F:\applications\nodejs\npm.cmd' 'start'
> bookworm-api#1.0.0 start F:\noise\bookworm-api
> nodemon --inspect --exec babel-node -- index.js
[nodemon] 1.18.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `babel-node --inspect index.js`
Debugger listening on ws://127.0.0.1:9229/e6e1ee3c-9b55-462e-b6db-4cf67221245e
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
Running on localhost:3333
The thing you're really looking for is:
Debugger listening on ws://127.0.0.1:9229/e6e1ee3c-9b55-462e-b6db-4cf67221245e
This output shows that your debugger is waiting on a WebSockets request on port 9229. You communicate that to visual studio code with:
"port": 9229,
In your launch.json file.
If you don't see the port that the debugging server is waiting on then you probably need to add the --inspect flag to your start command in node.
I get this same error when I forget to close the browser from the last debug session. It holds on to the connection to the Angular proxy and prevents a new debug session from starting up. Once I close the browser, F5 starts up a new session without error.
duplicate Google Chrome shortcut → itest
press alt key doubleclick itest
itest Properties → Shortcut → Target :
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --remote-debugging-port=6062 --user-data-dir="%appdata%\Google\Chrome\itest
VS Code, Menu Debug → Add Configuration → Chrome: Attach → "port": 6062, → Ctrl+Shift+D Debug → Switch Attach to Chrome → Start Debugging
Delete launch.json file and go to debug and create new launch.json file
Open Android Studio, Configure, ADV Manager, create or open an ADV.
In VS Code and in debug click emulate android cordova
Command line - cordova emulate android
{
"name": "cordova emulate android",
"type": "cordova",
"request": "launch",
"platform": "android",
"target": "emulator",
"port": 9222,
"sourceMaps": true,
"cwd": "${workspaceRoot}",
// "ionicLiveReload": true
},
I am using docker-compose to run a react express app. You can see the full compose file below.
I got the mentioned error, and I added a port mapping as follows to resolve the issue.
- "9229:9229"
Also the if you are using visual studio code, the address configuration in launch.json file inside of .vscode should be as follows.
"address": "0.0.0.0",
The full launch.json file is pasted below as well.
The full docker-compose.yml file looks as follows.
version: '3'
services:
proxy:
build:
context: ./proxy
ports:
- 7081:80
redis-server:
image: 'redis'
node-app:
restart: on-failure
build:
context: ./globoappserver
ports:
- "9080:8080"
- "9229:9229" ######### HERE IS THE FIX ##########
container_name: api-server
ui:
build:
context: ./globo-react-app-ui
environment:
- CHOKIDAR_USEPOLLING=true
ports:
- "7000:3000"
stdin_open: true
volumes:
- ./globo-react-app-ui:/usr/app
postgres:
image: postgres
volumes:
- postgres:/var/lib/postgresql/data
- ./init-database.sql:/docker-entrypoint-initdb.d/init-database.sql
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
volumes:
postgres:
Here is the launch.json file.
Take a look at this reference for this file settings.
{
// 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": "3",
"configurations": [
{
"name": "Docker: Attach to Node",
"type": "node",
"request": "attach", // The other option is launch
"port": 9229,
//"address": "localhost",
"address": "0.0.0.0",
//"localRoot": "D:\\Vivek\\MxWork\\Js\\GloboClientServer\\src\\globoappserver",
"localRoot": "D:/Vivek/MxWork/Js/GloboClientServer/src/globoappserver",
"remoteRoot": "/app",
"protocol": "inspector",
"skipFiles": [
//"<node_internals>/**",
"<node_internals>/**/*.js",
"${workspaceFolder}/**/node_modules/**/*.js"
]
//"program": "${workspaceFolder}\\src\\globoappserver\\index.js"
}
]
}
Go to Tools -> Options -> Debugging -> General
then disable
I'm using it successfully with the following options disabled.
In Visual Studio go to: Tools -> Options -> Debugging -> General
Enable JavaScript debugging for Asp.Net (Chrome, Edge, and IE)
Enable Legacy Chrome JavaScript debugger for ASP.NET.
In my case updating the core tools solved the issue.
Use the below command to update:
npm install -g azure-functions-core-tools
I digged all the net, but still can't find answer.
I run nodejs code with nginx on a remote VPS.
In the local project folder created the launch.json and can run debug mode on the server with F5 button. Local project folder only has .vscode with launch.json
This is launch.json
{
"version": "0.2.0",
"configurations": [{
"name": "attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "x.x.x.x",
"restart": true,
"sourceMaps": false,
"outFiles": [],
"localRoot": "${workspaceRoot}",
"remoteRoot": "/views/"
}]
}
On a server
[root#tri ~]# node --debug /usr/appfolder/views/index.js
Debugger listening on [::]:5858
Example app listening at http://:::5000
Through ngnix both index.js and css codes are accessible outside the server to the world.
But Visual Studio Code doesn't see this index.js to debug through.
I need to debug through remote code on VPS.
Thank You