I am testing the nest.js framework but I am struggling to run it with VSCode so that I can properly debug my code. This is pretty much the same issue as described here Running n
For people using Nrwl:
Launch.json (courtesy of @ghiscoding )
{
"type": "node",
"request": "attach",
"name": "Attach NestJS WS",
"port": 9229,
"restart": true,
"stopOnEntry": false,
"protocol": "inspector"
}
Terminal
ng serve nestjs_project --port 9229
This settings works for me
{
"name": "Launch app",
"type": "node",
"request": "launch",
"args": [
"src/main.ts"
],
"runtimeArgs": [
"-r",
"ts-node/register",
"-r",
"tsconfig-paths/register"
],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart",
"env": {
"NODE_ENV": "local",
"NODE_PORT": "9000"
},
"sourceMaps": true,
"console": "internalConsole",
"outputCapture": "std"
}
Get it from here
Here is a config that works. Hope this helps someone :)
Make sure you add tsconfig-paths/register
line under runtimeArgs
else you will get an error saying some of your user defined modules were not found.
Also replace <YOUR_APP_ROOT_FOLDER>
name with your application folder name if you have one under your root project folder, else remove it from the path in the script.
Note: Make sure to stop running your app before executing this debug config on vscode, because this debug script will launch a new instance of your app on the same port.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Nest Framework",
"args": [
"${workspaceFolder}/<YOUR_APP_ROOT_FOLDER>/src/main.ts"
],
"runtimeArgs": [
"--nolazy",
"-r",
"ts-node/register",
"-r",
"tsconfig-paths/register"
],
"sourceMaps": true,
"cwd": "${workspaceRoot}/<YOUR_APP_ROOT_FOLDER>",
"protocol": "inspector"
}
]
}
in launch.json have
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Nest Framework",
"args": ["${workspaceFolder}/src/main.ts"],
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"protocol": "inspector"
}
]
}