Appearance
Node.js debugging
TypeScript
Start with installing ts-node-dev and tsconfig-paths packages.
bash
yarn add ts-node-dev tsconfig-paths --dev
yarn add ts-node-dev tsconfig-paths --dev
1
Next up add debug script to package.json file. This command watches TypeScript files and restarts the node process when any file changes. The tsconfig-paths makes sure that custom module paths are resolved.
json
{
"scripts": {
"debug": "ts-node-dev -r tsconfig-paths/register ./src/index.ts"
}
}
{
"scripts": {
"debug": "ts-node-dev -r tsconfig-paths/register ./src/index.ts"
}
}
1
2
3
4
5
2
3
4
5
Finally add configuration for debugging to Visual Studio Code's launch.json. With this configuration VS Code executes yarn debug command.
json
{
"name": "Debug Node.js",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "yarn",
"runtimeArgs": [ "debug" ],
"env": {
"NODE_ENV": "dev"
}
}
{
"name": "Debug Node.js",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "yarn",
"runtimeArgs": [ "debug" ],
"env": {
"NODE_ENV": "dev"
}
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Start the debugging by pressing F5.