Alexander Mills Alexander Mills - 4 months ago 40
Node.js Question

Difference between $ node --debug and $ node debug

I am looking at the docs for

$ node --debug


$ node debug

there seem to be some behavioral differences between the two. The documentation should be here:

This part sort of explains the difference:

but not 100% following what it is saying.
Anyone know what the actual difference is between these too?


It's already explained in the documentation you linked to, under Advanced Usage:

An alternative way of enabling and accessing the debugger is to start Node.js with the --debug command-line flag or by signaling an existing Node.js process with SIGUSR1.

Once a process has been set in debug mode this way, it can be inspected using the Node.js debugger by either connecting to the pid of the running process or via URI reference to the listening debugger:

  • node debug -p <pid> - Connects to the process via the pid
  • node debug <URI> - Connects to the process via the URI such as localhost:5858
  • So in short, --debug (or SIGUSR1) explicitly enables the (V8) debug server and begins listening for debugger connections. Executing node debug localhost:5858/node debug -p 12345 then causes node's built-in command line debugger to connect to that particular process.

    Calling node debug foo.js is just a way to combine the two steps: enabling the debug server and then automatically connecting to it.