title: What is the proper way to debug an npm script using vscode?
body: <p>I've got an npm script that I'm trying to debug. I use vscode so I thought I'd create a debug configuration and step through it with the debugger. </p>
  
  <p>My npm script look is:</p>
  
  <pre><code>"scripts": {
      ...
      "dev": "node tasks/runner.js",
  }
  </code></pre>
  
  <p>So I created the following debug config:</p>
  
  <pre><code>{
      "version": "0.2.0",
      "configurations": [
          {
              "type": "node",
              "request": "launch",
              "name": "Launch Program",
              "runtimeExecutable": "npm",
              "cwd": "${workspaceRoot}",
              "runtimeArgs": [
                  "run", "dev"
              ],
              "port": 5858,
              "stopOnEntry": true
          }
      ]
  }
  </code></pre>
  
  <p>And when I fire it the script runs, but vscode is never able to connect and I get the error:</p>
  
  <blockquote>
    <p>Cannot connect to runtime via 'legacy' protocol; consider using 'inspector' protocol (timeout after 10000 ms).</p>
  </blockquote>
  
  <p>I tried adding an inspector protocol:</p>
  
  <pre><code>       {
              "type": "node",
              "request": "attach",
              "name": "Attach (Inspector Protocol)",
              "port": 9229,
              "protocol": "inspector"
         }
  </code></pre>
  
  <p>And running the npm script via:</p>
  
  <pre><code>npm run dev --inspect
  </code></pre>
  
  <p>And this time I get the error:</p>
  
  <blockquote>
    <p>Ensure Node was launched with --inspect. Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:9229).</p>
  </blockquote>
  
  <p>I'm not sure what part I'm missing. </p>
  
  <p><em>Edit per duplicate tag</em></p>
  
  <p>I see the other question re: debugging an npm script via vscode, but the details in the other question and answers aren't as detailed and specific. If someone is searching for the specific vscode error messages I ran into or the config type I had they wouldn't necessarily get the level answer detail that this question's chosen answer gives.</p>