Nestjs: right settings for debugging

gentax

paolo

Posted on March 1, 2023

Nestjs: right settings for debugging

Bored to use a lot of console.log() in your Nestjs application?
Want to become more productive and a better coder debugging directly in VSCode to find out what's wrong in your stack trace?

First thing first:
open to VSCode settings, then go to Extensions and then Javascript Debugger.
Find out Auto Attach Filter section and select Always from the dropdown.

Then, create a launch.json file in the .vscode folder of your project, then copy/paste the following code:



{
    "version": "0.2.0",
    "configurations": [
      {
        "type": "node",
        "request": "launch",
        "name": "Debug Nest Framework",
        "runtimeExecutable": "npm",
        "runtimeArgs": [
          "run",
          "start:debug",
          "--",
          "--inspect-brk"
        ],
        "autoAttachChildProcesses": true,
        "restart": true,
        "sourceMaps": true,
        "stopOnEntry": false,
        "console": "integratedTerminal",
      }
    ]
}


Enter fullscreen mode Exit fullscreen mode

It enables debug and console.log() at the same time.

thanks to Sasha Ladnov: https://stackoverflow.com/questions/49504765/debugging-nest-js-application-with-vscode/63325135#63325135

Be sure that in your package.json file there's the debug script:



"scripts": {
    ...
    "start:debug": "nest start --debug --watch",
    ...
}


Enter fullscreen mode Exit fullscreen mode

Now you're ready to debug your application!

Type yarn start:debug or npm run start:debug ...

Enjoy!

Debug and console.log() at the same time


Debug and console.log() at the same time

💖 💪 🙅 🚩
gentax
paolo

Posted on March 1, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related