21
loading...
This website collects cookies to deliver better user experience
Ctrl+Shift+D
on your keyboard), followed by the Run and Debug button at the top left corner of the application.launch.json
in the .vscode
folder at the root of the project.launch.json
file should appear in the editor with the following contents:// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch URL Shortener",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/src/server.js"
}
]
}
name
of the configuration is how it will be identified in the Configurations menu; the program that will run is specified in the program
field.$ node --inspect src/server.js
$ node --inspect-brk src/server.js
Ctrl+Shift+P
and find the Debug: Attach to Node Process command:curl
.console.log()
statement that is easy to add and remove without editing the code itself. It is represented by a red diamond-shaped icon in place of the red circle.sourceMap
in your tsconfig.json
file:{
"compilerOptions": {
"sourceMap": true
}
}
node_modules
folder.outFiles
attribute in your launch configuration file to specify the exact location where Visual Studio Code must look for source maps; this should be the location of the JavaScript output:{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch TypeScript",
"skipFiles": [
"<node_internals>/**"
],
"preLaunchTask": "compile",
"program": "${workspaceFolder}/src/server.ts",
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
}
]
}
ts-node
to run your project without a build step, the process is simpler. Instead of using the launch.json
configuration above, use the following:{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Server",
"skipFiles": [
"<node_internals>/**"
],
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/src/server.ts"
]
}
]
}
program
attribute, so runtimeArgs
registers ts-node
as the handler for TypeScript files, and the first argument to args
is the entry file for the program. Once this is set up, you can start a debugging session!