Search This Blog

Thursday, July 9, 2020

Debug React app on VSCode

Start server side with 
node --inspect server.js 

debugger will listen on 9229 ..

Create a launch.json for debug
==========

{
// 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 Chrome",
"request": "launch",
"type": "pwa-chrome",
"url": "http://localhost:8015",
"webRoot": "${workspaceFolder}"
},
{
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node"
}
]
}
======================

To do front end debug... install chrome ext on vscode.
start your front end via the npm start or check package.json for run scripts.
Use the above configuration 
It will launch a chrome on 8015. also make sure your front end is started on 8015

...time to debug... you should see breakpoints hitting.... 
you can also add debugger;  in your code , its same as a breakpoint..
var i = "helo";
debugger;                <============== Break point will be activated here...
console.log('value is ' +i) 




No comments:

Post a Comment