記事内に広告が含まれています。

Visual Studio Code と node.js で JavaScript をデバッグ実行する方法

2017年8月23日

手順

  • node.js をインストールします。
  • Visual Studio Code をインストールします。
  • 任意のフォルダにデバッグ対象となる js ファイルを生成します。(ここでは仮に app.js とします。)
  • Visual Studio Code の「デバッグ」ボタンを押して、「launch.json を開く」ボタンを押します。
  • launch.json の configurations - program に "${workspaceRoot}/app.js" と記述します。
{
    // Use IntelliSense to learn about possible Node.js debug 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",
            "program": "${workspaceRoot}/app.js"
        }
    ]
}
  • Visual Studio Code で app.js を開き、ブレークポイントを設定、もしくは app.js 内に debugger キーワードを記述します。
  • 「Launch Program」ボタンをクリックするとデバッグが開始します。

実行結果

 

-Visual Studio Code