NestJS: VSCode debugger setup

Debugging is inevitable for all developers and when you get the point that your code is not doing what you would expect

VSCode is definitely built for TypeScript and thus perfect for NestJS. Get started by ensuring you have VSCode installed and open your project in VSCode. For the purpose of this article install the Nest TypeScript starter scaffolding.

    $ npm i -g @nestjs/cli
    $ nest new my-app

Create a launch.json file:

    {
        // 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": "Launch Program",
                "skipFiles": [
                    "${workspaceFolder}/node_modules/**/*.js",
                    "<node_internals>/**"
                ],
                "program": "${workspaceFolder}/src/main.ts",
                "preLaunchTask": "tsc: watch - tsconfig.build.json",
                "outFiles": [
                    "${workspaceFolder}/dist/**/*.js"
                ]
            }
        ]
    }

Now you can set breakpoints and Debug -> Start Debugging or press F5.

Since you've made it this far, sharing this article on your favorite social media network would be highly appreciated 💖! For feedback, please ping me on Twitter.