48

Is there a command line argument or an environment variable that disables the "break on first line" feature of the node debugger?

Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168

7 Answers7

35

There are actually two debugger concepts in node: V8 debugger (with its TCP-based protocol) and a node command-line debugger (CLI).

When you run node debug app.js, a debugger CLI is run in the master node process and a new child node process is spawned for the debugged script (node --debug-brk app.js). The option --debug or --debug-brk is used to turn on V8 debugger in the child process.

The difference between --debug and --debug-brk is that the latter one adds a breakpoint on the first line, so that execution immediately stops there.

I would suggest you this solution:

  1. When you are creating a child process from your webserver, run node --debug instead of node debug. This way there is only one child process created, it is running your application and it is not paused on the first line.

  2. Now you can use any debugging tool that supports V8 debugger protocol - node built-in CLI debugger, node-inspector or you can event implement your own debugger front-end (GUI) if you like. (I presume this is what you are trying achieve by running CLI debugger in background?)

    If you decided to use built-in CLI, just spawn another another child process and tell node CLI debugger to connect to the process started in step 1:

    node debug localhost:5858

    and continue as before.

Miroslav Bajtoš
  • 10,667
  • 1
  • 41
  • 99
  • Thanks Miroslav for your answers both here and on Github! What we are doing is building a web debugger client for an internal web framework we have build. We are still missing the "disable break on first line" feature. The lack of this feature probably force us to use an extra process in our stack or hardcode the `c` (continue). We have now all this info now: `SIGUSER1`, `--debug`, `--debug-brk`, etc. We will for sure figure out/hack something. :) – Gabriel Petrovay May 22 '13 at 21:45
  • The thing I don't understand: why do you use CLI interface to communicate from webserver to debugged process? Why don't you use V8 debugger protocol directly? You can look at CLI implementation to see how the commands are translated to V8 requests: https://github.com/joyent/node/blob/master/lib/_debugger.js – Miroslav Bajtoš May 23 '13 at 06:32
  • Yes, we will use the V8 protocol (that's why the question on the node mailing list you answered: https://groups.google.com/forum/?fromgroups#!topic/nodejs/h6lYK3i6KTA). We have done a proof-of-concept that was running based on the CLI. But, yes, the V8 protocol is the right solution. – Gabriel Petrovay May 23 '13 at 08:56
24

According this issue I have opened in the node repo, currently, this is not possible. This is also something that the node guys don't see as a feature worth implementing "because it seems kind of pointless. […] Attaching to a running process does exactly" the same thing. See the rest of the discussion in the mentioned issue.

If you think you want such a feature, vote this up, leave a comment in the Github issue, and, if no response, open a new one and post it here as well.

JohnAllen
  • 7,317
  • 9
  • 41
  • 65
Gabriel Petrovay
  • 20,476
  • 22
  • 97
  • 168
7

Found this while looking for the answer myself - Seems that you can simply run

node-debug --debug-brk=0 (progname)

Hope this helps someone.

jnadro52
  • 3,454
  • 3
  • 21
  • 17
1

Write a chrome extension to click the start button

1. Run shell

mkdir run_as_devtools
cd run_as_devtools
touch manifest.json
touch run_as_devtools.js

2. Edit the files

run_as_devtools.js:

if (location.protocol === 'chrome-devtools:' && location.href.match(/ws=localhost/))(function () {
    'use strict';
    setTimeout(function () {
        try {
            document.querySelector('html /deep/ .long-click-glyph').click();
        } catch (e) {
            console.log(e);
        }
    }, 500);    
})();

manifest.json: (it uses chromevox's key, so don't use it with chromevox)

{
   "content_scripts": [{
      "js": [ "run_as_devtools.js" ],
      "matches": [ "<all_urls>" ]
   }],
   "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDEGBi/oD7Yl/Y16w3+gee/95/EUpRZ2U6c+8orV5ei+3CRsBsoXI/DPGBauZ3rWQ47aQnfoG00sXigFdJA2NhNK9OgmRA2evnsRRbjYm2BG1twpaLsgQPPus3PyczbDCvhFu8k24wzFyEtxLrfxAGBseBPb9QrCz7B4k2QgxD/CwIDAQAB",
   "manifest_version": 2,
   "name": "Elevated Devtools extension",
   "version": "1.0"
}

3. Install the extension

Chrome settings - More tools - Extensions- Developer mode - Load unpacked extension - select run_as_devtools folder

P.S. Better to use it with Node inspector manager https://stackoverflow.com/a/43018133/4831179

Reference: https://stackoverflow.com/a/17044405/4831179

Community
  • 1
  • 1
blackmiaool
  • 5,234
  • 2
  • 22
  • 39
1

I solved same issue just by switching from node v6 to v7

Sami
  • 8,168
  • 9
  • 66
  • 99
0

Similar to blackmiaool's idea but simpler, with node v8 you can start the script with --inspect. If you have the following code in it, when you open the debug window in Chrome devtools it will take you straight to the debugger point. Additionally this allows you to execute async code by hitting the "continue" button, which allows your code to run before returning you to the repl:

// app_shell.js

var UserModel = require("./some_user_model");

function looper() {
    var Tmp = { UserModel: UserModel };
    debugger;
    setTimeout(looper, 100);
}
looper();

And in a shell script you can do something like:

echo "Click the 'Open dedicated DevTools for Node' link"
python -mwebbrowser about:inspect
node --inspect app_shell.js

See here for more info

AJP
  • 26,547
  • 23
  • 88
  • 127
0

This worked for me .

node --inspect index.js

If you haven't install inspector , install it as receommended by node docs:

npm install -g node-inspect
Redmen Ishab
  • 2,199
  • 18
  • 22