This article discuss how to debug Angular/Node.js application in WebStorm and VSCode.
Debug Angular app
WebStorm
- Start angular application
1
npm start // or ng serve
- Set breakpoints in the source code in WebStorm Editor.
- Press
Ctrl + Shift+Clickon the URL in the terminal to open the browser.
- See here for more details.
VSCode
Launch with task file
- Create file
launch.jsonunder.vscodefolder in project root.1
2
3
4
5
6
7
8
9
10
11
12
13{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "debug angular app",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: start",
"url": "http://localhost:4200/"
},
]
} - Create file
task.jsonunder.vscodefolder in project root.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24{
// For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"background": {
"activeOnStart": true,
"beginsPattern": {
"regexp": "(.*?)"
},
"endsPattern": {
"regexp": "bundle generation complete"
}
}
}
},
]
} - Click
Run and Debugin VSCode’s left side menu. // number 1 on picture below - Select
debug angular appin the dropdown list. // number 2 on picture below - Click the Debug icon or Press
F5to start debugging. // number 3 on picture below
In this way, VSCode will open a new Chrome window and you can debug the Angular app in VSCode.
Launch without task file
If you don’t want to use task.json file, you can remove it and delete preLaunchTask in launch.json file. Then
- Manually start the Angular app by
npm startin terminal. - Click the Debug icon or Press
F5to start debugging in VSCode.
In this way you need to manually open the browser and navigate tohttp://localhost:4200/to debug the Angular app.
Browser
No matter you use WebStorm or VSCode, you can also debug Angular app in browser.
- Run your angular app by
npm run startorng serve - Open the browser and navigate to
http://localhost:4200/. - Press
F12to open the developer tools and switch toSourcetab. - Set breakpoint in your source code in browser. see here for more details.
- If you use webpack, the source file was in
webpack://srcfolder. - If you use ESBuild + Vite, the source files were in
srcfolder.
- If you use webpack, the source file was in
- Refresh the page to trigger the breakpoints.