![]() ![]() Once the breakpoint is hit, you can step through the code and do everything you would when debugging a JavaScript app.Īttaching debugger to the running node process Put the breakpoints and start the debug configuration ( Ctrl-D on macOS or Shift+F9 on Windows & Linux). Specify the path to the compiled JavaScript file that starts the app. Now let’s create a new Node.js debug configuration (select Run – Edit configurations – Add). In our example, we need to run npm run build for that. The right way to it depends of the configuration of the app’s build pipeline. ![]() We’ll use the TypeScript Express sample project as an example here.įirst, we need to compile the app to JavaScript. To enable source map generation, add "sourceMap": true in the tsconfig.json file. The TypeScript compiler can generate the source maps. WebStorm’s debugger will use them to map the compiled code that is executed to the source code in the editor, and you will be able to put breakpoints in TypeScript code and step through it. There’s one extra thing you need for that – Source Maps. With WebStorm you can also debug code written in TypeScript (though you need to compile it to JavaScript first to run it with node). For any earlier versions it will use the old options and protocol. WebStorm will check the node version you’re using and if it’s 8+, it will use the new options and protocol. With WebStorm, you don’t have to worry about the protocols and options. The command-line options that you need to use to start debugging have changed to -inspect and -inspect-brk. Debugging protocolsĪs you may know, in version 7+ Node.js changed its debugging protocol to the Chrome Debugging Protocol. Tip: another way to quickly run or debug a Node.js file is using the Run or Debug actions in the context menu of the JavaScript file. Explore the call stack and the variables in the debugging tool window, hover over the expressions in the editor to see their current state, step through the code, or put new breakpoints to help you debug further. Now if you do the actions that trigger the code where the breakpoint is, the app will pause on the breakpoint. If you just want to run the app, click the green run icon next instead or press Ctrl-D / Shift + F10.Now press Ctrl-D on macOS or Shift+F9 on Windows & Linux to debug the app (or click the green bug-like icon). Now specify the path to the main file of the application that starts it. ![]()
0 Comments
Leave a Reply. |