How to debug Node.js code

Are you tired of so many console.log();?, Of course, As it was very difficult to debug 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

Step 1: Open the Visual Studio code with Node.Js file to be debugged

Step 2: 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" }] }

Step 3: Then you can click on the debug icon present in the Visual Studio and select the breakpoint where you want to start the debugging

Demo :