This is my first time trying to setup Nodejs with debugger tool. My lauch.json code is:
{
// 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",
"program": "${workspaceFolder}/app.js"
},
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
}
]
}
When I run the debugger in VS code and go to debug console. I get:
C:\Program Files\nodejs\node.exe --inspect-brk=29182 app.js
Debugger
listening on ws://127.0.0.1:29182/c2a39cf7-ab13-4sd1b-afs5-eb9wqwq5de9
I have setup a breakpoint on my app.js as well.
I have tried to go to the
ws://127.0.0.1:29182/c2a39cf7-ab13-4sd1b-afs5-eb9wqwq5de9
url as shown in the debugger but it give me:
Site cannot be reached
error in chrome
No this is the port where debugger is listening you are not supposed to go to that path,you will go to your port where your nodejs server is listening and debugger will listen to that.
For Example:
I have a node server running on port 3000 and I have a get request like this
app.get('/',()=>{
console.log("This is get request");
})
and I have a break point on this line: console.log("This is get request");. I will start server by running debugger.
Then I will go to localhost:3000 from postman to check and debugger will called automatically.
Related
I am working on a node.js application using express.js as a web framework listening on PORT 3000.
I am using VS Code v1.46.
My launch.json file is
{
// 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",
"program": "${workspaceFolder}\\WebApi\\index.js",
"restart": true,
"protocol": "inspector"
}
]
}
I am able to start the debugging session for the first time, but 2nd time onwards, I get error Error: listen EADDRINUSE: address already in use :::3000
This error is because VSCode didn't terminate the node.exe process created in 1st debugging session and so in the subsequent session node failed to start the express server on port 3000 as it is still in used.
Can anyone help me to configure VSCode to terminate node.exe process once I stop the debugger?
This issue started just last week for me, not sure why, maybe windows update.
Any way I found the following :
https://github.com/OmniSharp/omnisharp-vscode/issues/2387
where they say that if you add to launch.json
"console": "externalTerminal" or "console": 'integratedTerminal'
it will open a console for the process so that u can kill manually
It works fine with the Using the "preview" debug extension.
This is the launch.json for using that mode, just make sure that you put the correct command of your package.json.
{
"version": "0.2.0",
"configurations": [
{
"type": "node-terminal",
"name": "Run Script: start",
"request": "launch",
"command": "npm run start",
"cwd": "${workspaceFolder}"
}
]
}
Node js Version :v8.11.3
VS Code version :1.29.1 x64
npm version :6.6.0
Hi ,
I have created a default express skeleton project using express --view=jade myapp command after that cd myapp/ and npm install in the last.
Now I am trying to attach vscode debugger to this newly created project but no luck.
This is the content of my launch.json
{
// 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",
"protocol":"inspector",
"port":3000,
"program": "/home/pankaj/myfirstapp/myapp/app.js"
}
]
}
I am also not able to see any error in the debug console .There is nothing in debug console neither success nor failure.
Thanks In advance
Be careful for express default setup to set the path of program in launch.json to "program": "${workspaceFolder}/bin/www"
Port 3000 is the application port of your express application. If you specify this in your launch configuration, the VS Code debugger will try to use it as the debug port (which obviously cannot work).
In addition, use VS Code variables to specify where your programs lives. E.g. if you have opened VS Code on your myapp directory, use ${workspaceFolder}/app.js for the program attribute:
E.g.:
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/app.js"
}
I'm locally developing a Node.js app with Azure Functions Core Tools. I would like to debug it with help of VS Code debugger, but I get this error:
Cannot connect to runtime process, timeout after 10000 ms - (reason:
Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:5858)
For debug option, I've chosen "Attach to JavaScript Functions". This option was there by default and I haven't created it.
Here is content of my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to JavaScript Functions",
"type": "node",
"request": "attach",
"port": 5858,
"preLaunchTask": "runFunctionsHost"
}
]}
How can I fix this issue and make the debugging to work?
Surprisingly issue was resolved by itself. So I close this issue.
I'm building an express.js application that I'm testing using Postman. I haven't needed debugging until now, but I've just tried to set it up and run into a bit of an issue.
I followed this tutorial, but it isn't working for me as the end result of the tutorial shows that it should.
I built myself a launch.json file with a configuration built to handle running using nodemon...
"configurations": [
{
"type": "node",
"request": "launch",
"name": "nodemon",
"runtimeExecutable": "nodemon",
"program": "${workspaceFolder}/app.js",
"restart": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\bin\\www"
}
]
I then started the debugger and got the following output in my terminal...
C:\Users\User\AppData\Roaming\npm\nodemon.cmd --inspect=35939 --debug-brk app.js
[nodemon] 1.14.11
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting node --inspect=35939 --debug-brk app.js
Debugger listening on
ws://127.0.0.1:35939/fca1b410-e096-4189-a5b2-bf266755e89e
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
(node:24832) [DEP0062] DeprecationWarning: node --inspect
--debug-brk is deprecated. Please use node --inspect-brk instead.
To test it out, I put a break-point on the very first line of my app.js file. The break-point was hit successfully.
I went into the router file and put a break-point inside the post method that I needed to debug...
//POST New Trip page//
router.post('/newtrip', function (req, res) {
return tripCtrl.create(req, res); <---- BP on this line
});
I then ran the Postman request that I have been using to test this method:
(POST) http://localhost:3000/newtrip
I was fully expecting my new break-point to be hit, but the break-point wasn't hit, and I got no output from my debugger console or terminal. All I have is Postman returning 'Could not get any response'.
I'm well and truly lost as to where to go. Can anyone spot what might be wrong here please?
This is my file structure for the project:
Thanks,
Mark
This is the minimum configuration of lanuch.json required to debug in vscode based on your start command. Try updating with this to debug.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/bin/www"
}
]
}
Hello i have problem with debug my app of node and visual studio code. When i tried run debug in visual i saw text " Debugger listening on port 30108
" but when i open my browser on localhost:30108 there is only information somethig like this
Type: connect
V8-Version: 4.5.103.36
Protocol-Version: 1
Embedding-Host: node v4.4.7
Content-Length: 0
on localhost:3000 (default app port) there is only error
" This site is unreachable "
So how to do, to be able to debug app with running app in browser ?
If you do a node app.js or npm start (or whatever for your project) in a terminal/command window, does your project also start successfully? Which OS are you using? Any firewall issues going on?
If you can access the site in your browser outside of VS Code, check my "Third attempt" documented here. Essentially, you need to edit both your launch.json and your package.json to indicate the port you are going to use. My examples follow the npm run {script name} format. You should be able to tailor it to suit.
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "npm.cmd",
"runtimeArgs": [
"run", "start"
],
"port": 5858,
"skipFiles": [
"<node_internals>/**/*.js"
]
}
]
}
package.json
"scripts": {
"start": "node --inspect=5858 src/app.js",
}
Essentially, you need to ensure you are launching your app the same way you would from the command line. Then, ensure you have the matching port info in both files (and their respective locations) mentioned above.
More info available here for alternate/additional configuration options for debugging.