|
| 1 | +--- |
| 2 | +title: Inspector Help |
| 3 | +layout: docs.hbs |
| 4 | +--- |
| 5 | + |
| 6 | +# Debugging Node.js Apps |
| 7 | + |
| 8 | +Many tools and libraries are available to help you debug your Node.js apps. Some |
| 9 | +of these are listed below. |
| 10 | + |
| 11 | +To connect manually rather than with a tool, pass the **--inspect** flag and |
| 12 | +connect to the printed URL. |
| 13 | + |
| 14 | +If a process was started without `--inspect`, signal it with SIGUSR1 to |
| 15 | +activate the debugger and print the connection URL. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Inspector Tools & Clients |
| 20 | + |
| 21 | +These commercial and open source tools make debugging Node.js apps easier. |
| 22 | + |
| 23 | +### [node-inspect](https://github.com/nodejs/node-inspect) |
| 24 | + |
| 25 | +* A CLI debugger developed at <https://github.com/nodejs/node-inspect>. |
| 26 | +* Bundled with Node and invoked with `node inspect myscript.js`. |
| 27 | +* Can also be installed independently with `npm install -g node-inspect` |
| 28 | + and invoked with `node-inspect myscript.js`. |
| 29 | + |
| 30 | +### [Chrome DevTools](https://github.com/ChromeDevTools/devtools-frontend) 55+ |
| 31 | + |
| 32 | +* **Option 1**: Open `chrome://inspect` in a Chromium-based |
| 33 | + browser. Click the Configure button and ensure your target host and port |
| 34 | + are listed. Then select your Node.js app from the list. |
| 35 | +* **Option 2**: Install the Chrome Extension NIM (Node Inspector Manager): |
| 36 | + https://chrome.google.com/webstore/detail/nim-node-inspector-manage/gnhhdgbaldcilmgcpfddgdbkhjohddkj |
| 37 | + |
| 38 | +### [VS Code](https://github.com/microsoft/vscode) 1.10+ |
| 39 | + |
| 40 | +* In the Debug panel, click the settings icon to open `.vscode/launch.json`. |
| 41 | + Select "Node.js" for initial setup. |
| 42 | + |
| 43 | +### [Visual Studio](https://github.com/Microsoft/nodejstools) |
| 44 | + |
| 45 | +* Choose "Debug > Start Debugging" from the menu or hit F5. |
| 46 | +* [Detailed instructions](https://github.com/Microsoft/nodejstools/wiki/Debugging). |
| 47 | + |
| 48 | +### [JetBrains WebStorm](https://www.jetbrains.com/webstorm/) 2017.1+ and other JetBrains IDEs |
| 49 | + |
| 50 | +* Create a new Node.js debug configuration and hit Debug. |
| 51 | + |
| 52 | +### [chrome-remote-interface](https://github.com/cyrus-and/chrome-remote-interface) |
| 53 | + |
| 54 | +* Library to ease connections to Inspector Protocol endpoints. |
| 55 | + |
| 56 | +--- |
| 57 | + |
| 58 | +## Command-line options |
| 59 | + |
| 60 | +The following table lists the impact of various runtime flags on debugging: |
| 61 | + |
| 62 | +<table cellpadding=0 cellspacing=0> |
| 63 | + <tr><th>Flag</th><th>Meaning</th></tr> |
| 64 | + <tr> |
| 65 | + <td>--inspect</td> |
| 66 | + <td> |
| 67 | + <ul> |
| 68 | + <li>Enable inspector agent</li> |
| 69 | + <li>Listen on default port (9229)</li> |
| 70 | + </ul> |
| 71 | + </td> |
| 72 | + </tr> |
| 73 | + <tr> |
| 74 | + <td>--inspect=<i>port</i></td> |
| 75 | + <td> |
| 76 | + <ul> |
| 77 | + <li>Enable inspector agent</li> |
| 78 | + <li>Listen on port <i>port</i></li> |
| 79 | + </ul> |
| 80 | + </td> |
| 81 | + </tr> |
| 82 | + <tr> |
| 83 | + <td>--inspect-brk</td> |
| 84 | + <td> |
| 85 | + <ul> |
| 86 | + <li>Enable inspector agent</li> |
| 87 | + <li>Listen on default port (9229)</li> |
| 88 | + <li>Break before user code starts</li> |
| 89 | + </ul> |
| 90 | + </td> |
| 91 | + </tr> |
| 92 | + <tr> |
| 93 | + <td>--inspect-brk=<i>port</i></td> |
| 94 | + <td> |
| 95 | + <ul> |
| 96 | + <li>Enable inspector agent</li> |
| 97 | + <li>Listen on port <i>port</i></li> |
| 98 | + <li>Break before user code starts</li> |
| 99 | + </ul> |
| 100 | + </td> |
| 101 | + </tr> |
| 102 | + <tr> |
| 103 | + <td><code>node inspect <i>script.js</i></code></td> |
| 104 | + <td> |
| 105 | + <ul> |
| 106 | + <li>Spawn child process to run user's script under --inspect flag; |
| 107 | + and use main process to run CLI debugger.</li> |
| 108 | + </ul> |
| 109 | + </td> |
| 110 | + </tr> |
| 111 | +</table> |
| 112 | + |
0 commit comments