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
What I did was auto attach the vs code debugging process with one of my scripts in package.json. And on top of it I used nodemon, which would automatically restart up along with the debugger, if you have made any changes in development.
The process requires you to install nodemon globally and add a nodemon-debug.json file in the root of the folder, which looks like this.
nodemon-debug.json
{
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register src/main.ts"
}
Then in the package.json, add a script that looks like this
"debug": "nodemon --config nodemon-debug.json"
Then in the VS Code, hit F1 > search for Debug: Toggle Auto Attach. Hit on it to enable it.
Then start up the debugging process by running the following command -
npm run debug
The debugger automatically turns on.
The advantage of this process is nodemon, which automatically starts along with the debugger every time you make some changes in the code and need it up.
For a more detailed explanation, go through this link. Worked for me.