| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8966ab3 commit 3bfc9f5
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,8 +6,12 @@ | |||
| 6 | 6 | ||
| 7 | 7 | <!-- type=misc --> | |
| 8 | 8 | ||
| 9 | - Node.js includes a command-line debugging utility. To use it, start Node.js | ||
| 10 | - with the `inspect` argument followed by the path to the script to debug. | ||
| 9 | + Node.js includes a command-line debugging utility. The Node.js debugger client | ||
| 10 | + is not a full-featured debugger, but simple stepping and inspection are | ||
| 11 | + possible. | ||
| 12 | + | ||
| 13 | + To use it, start Node.js with the `inspect` argument followed by the path to the | ||
| 14 | + script to debug. | ||
| 11 | 15 | ||
| 12 | 16 | ```console | |
| 13 | 17 | $ node inspect myscript.js | |
@@ -25,40 +29,26 @@ Break on start in myscript.js:2 | |||
| 25 | 29 | debug> | |
| 26 | 30 | ``` | |
| 27 | 31 | ||
| 28 | - The Node.js debugger client is not a full-featured debugger, but simple step and | ||
| 29 | - inspection are possible. | ||
| 30 | - | ||
| 31 | - Inserting the statement `debugger;` into the source code of a script will | ||
| 32 | - enable a breakpoint at that position in the code: | ||
| 33 | - | ||
| 34 | - <!-- eslint-disable no-debugger --> | ||
| 32 | + The debugger automatically breaks on the first executable line. To instead | ||
| 33 | + run until the first breakpoint (specified by a [`debugger`][] statement), set | ||
| 34 | + the `NODE_INSPECT_RESUME_ON_START` environment variable to `1`. | ||
| 35 | 35 | ||
| 36 | - ```js | ||
| 36 | + ```console | ||
| 37 | + $ cat myscript.js | ||
| 37 | 38 | // myscript.js | |
| 38 | 39 | global.x = 5; | |
| 39 | 40 | setTimeout(() => { | |
| 40 | 41 | debugger; | |
| 41 | 42 | console.log('world'); | |
| 42 | 43 | }, 1000); | |
| 43 | 44 | console.log('hello'); | |
| 44 | - ``` | ||
| 45 | - | ||
| 46 | - Once the debugger is run, a breakpoint will occur at line 3: | ||
| 47 | - | ||
| 48 | - ```console | ||
| 49 | - $ node inspect myscript.js | ||
| 50 | - < Debugger listening on ws://127.0.0.1:9229/621111f9-ffcb-4e82-b718-48a145fa5db8 | ||
| 45 | + $ NODE_INSPECT_RESUME_ON_START=1 node inspect myscript.js | ||
| 46 | + < Debugger listening on ws://127.0.0.1:9229/f1ed133e-7876-495b-83ae-c32c6fc319c2 | ||
| 51 | 47 | < For help, see: https://nodejs.org/en/docs/inspector | |
| 52 | 48 | < | |
| 49 | + connecting to 127.0.0.1:9229 ... ok | ||
| 53 | 50 | < Debugger attached. | |
| 54 | 51 | < | |
| 55 | - ok | ||
| 56 | - Break on start in myscript.js:2 | ||
| 57 | - 1 // myscript.js | ||
| 58 | - > 2 global.x = 5; | ||
| 59 | - 3 setTimeout(() => { | ||
| 60 | - 4 debugger; | ||
| 61 | - debug> cont | ||
| 62 | 52 | < hello | |
| 63 | 53 | < | |
| 64 | 54 | break in myscript.js:4 | |
@@ -252,5 +242,6 @@ Chrome DevTools doesn't support debugging [worker threads][] yet. | |||
| 252 | 242 | [ndb][] can be used to debug them. | |
| 253 | 243 | ||
| 254 | 244 | [Chrome DevTools Protocol]: https://chromedevtools.github.io/devtools-protocol/ | |
| 245 | + [`debugger`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger | ||
| 255 | 246 | [ndb]: https://github.com/GoogleChromeLabs/ndb/ | |
| 256 | 247 | [worker threads]: worker_threads.md | |
| Back | FazBrowse Home | New Git URL |
0 commit comments