How to debug Node.js code using Visual Studio Code



Are you tired of so many console.log();?, Of course, As it was very difficult to debug the node.js application in real-time When I say debug, not the traditional console.log mechanism. Debug like you are doing the Java debugging using Eclipse and Intellij tools.


But when Chrome 55 started supporting the Node.js debugger then magic happened and all the Node.js developers were excited to use these features and later on, this debugging facility has been implemented by most of the code editors.


And Node.js code is a family of JavaScript and TypeScript so with no doubt you should prefer Visual Studio code, one of the best free open source code editor for JavaScript projects and with Visual Studio Code 1.10+, you can use the option to debug the code directly from the editor and believe me it's awesome !!


So let's get into action and see how to debug Node.js code  

  • Open the Visual Studio code with Node.Js file to be debugged
  • In the launch.json add the configuration as below

{
  "version": "0.2.0",
  "configurations": [{
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceFolder}\index.js"
  }]
}
  • Then you can click on the debug icon present in the Visual Studio and select the breakpoint where you want to start the debugging


0
0
icon
lal chand teli 26-Nov-2021, 11:59 AM

thank you sir! for this