# Simple debugging

VS Code includes a debugger for Node.js out-of-the-box. You can run any JavaScript file with the debugger without any configuration whatsoever.&#x20;

### Simple Debugging

{% tabs %}
{% tab title="Exercise" %}
Debug the "index.js" file in the "1-simple-debugging" folder and inspect the `response.data.results` object
{% endtab %}

{% tab title="Answer" %}

* Open the "index.js" file in the "1-simple-debugging" folder
* Click in the left-hand margin next to line 12 to add a red dot

![](https://1151923643-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm0zhX7H5Kp1XYLtYbA%2Fimage.png?alt=media\&token=f847f2c8-6c37-49c6-b43c-657aecfdac6c)

* Press **F5**
* Select "Node.js" from the prompt

![](https://1151923643-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm1--pPjDkoPfQbJMXQ%2Fimage.png?alt=media\&token=3e32460b-0915-4c2d-a04c-08ff8551e5cb)

* The application will run and the breakpoint will be hit
* VS Code will also open the debug panel
* Expand the "response" object on the right-hand side under "variables" and file the "results" object

![](https://1151923643-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm1-UiElbAubsDH2Im9%2Fimage.png?alt=media\&token=94e269c0-5eae-40b1-a163-7c026e6af050)

{% hint style="info" %}
Note that you can also use the "Debug Console" in the bottom Panel and just enter the name of the command or object you want to run/inspect.
{% endhint %}

![](https://1151923643-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm1-ppFtR15aKX7lkpa%2Fimage.png?alt=media\&token=94d84405-c9cb-4c5b-bffe-764eb81e860d)

![](https://1151923643-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm1-vpMDWTyPk8ylh_e%2Fimage.png?alt=media\&token=552a707f-c5b3-4a37-a432-06295f0b71c4)
{% endtab %}
{% endtabs %}

### Logpoints

While debugging is normally associated with breakpoints, VS Code has a concept called "Logpoints" . These are breakpoints that simply log out values to the Debug Console. This is useful for when you want to simply inspect a value, but you don't want to have the whole application halt. It's a nice substitute for `console.log`.

{% tabs %}
{% tab title="Exercise" %}
Add a log point to the application to log the value of `response.data.results` to the Debug Console. Run the app and view the log.
{% endtab %}

{% tab title="Answer" %}

* Right-click the left-hand gutter next to line 12 and select "Add Logpoint"

![](https://1151923643-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm12qnMk9KdiLHsfBwl%2Fimage.png?alt=media\&token=54ef3be4-ed28-48c3-b638-0c9395b0824c)

* Enter `Response object is: {response.data.results}` and press **Enter**

![If you want an expression evaluated, you must wrap it in {}](https://1151923643-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm13JJGIGwPiIwV6A9X%2Fimage.png?alt=media\&token=d96065bf-58b5-438f-aeaf-1a1d0e5d230c)

* Press **F5** to run the "index.js" file with VS Code
* View the Logpoint output in the Debug Console

![](https://1151923643-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LlvtEHKkq5bvzPq1pJ4%2F-Lm5WIB-swfdJcB6Is3B%2F-Lm15xiPQs2AgT29com4%2Fimage.png?alt=media\&token=07f95efc-65ca-4ae7-a3d5-130c72d965ae)

{% hint style="info" %}
Note that if your Logpoint is not being logged out, it may be because you have a syntax error. If you have double-checked and it is still not being loaded, reload the VS Code window by opening the Command Palette (**Cmd/Ctrl + Shift + P**) and selecting "Reload Window".
{% endhint %}
{% endtab %}
{% endtabs %}
