Using Node Inspector with multiple node processes

If you use Chrome, then you can also use devtools directly with url like:

devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/0cc79945-8386-4082-aabb-328341bfc953

*where 9229/0cc79945-8386-4082-aabb-328341bfc953 - part can be taken from node's output


For example, run first app with:

$ node --inspect-brk=7777 app.js
Debugger listening on ws://127.0.0.1:7777/2df21a01-44ff-40c4-b6ff-1f839f81f9d6

and so the result url will be:

devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:7777/2df21a01-44ff-40c4-b6ff-1f839f81f9d6

then run second app instance with:

$ node --inspect-brk=7778 app.js
Debugger listening on ws://127.0.0.1:7778/d4e8d8ce-abe9-46c6-89b1-ad0616bdf237

and open it with:

devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:7778/d4e8d8ce-abe9-46c6-89b1-ad0616bdf237

Attach the debugger

Either by port or by process id. For ports, use a different port for each process. On the command line:

node --inspect 8085 some_script_1.js
node --inspect 8086 some_script_2.js
node --inspect 9012 some_script_3.js

In a separate terminal window, you can attach to any of these processes with node inspect <host>:<port>. For example to attach to some_script_2.js on port 8086

node inspect 127.0.0.1:8086

Attaching to different processes is matter of changing the port, for example 9012 you would run

node inspect 127.0.0.1:9012

If you didn't start node on a separate, known port, you can also use the -p flag to attach directly to an existing process

node inspect -p <node_script_process_id>

On Linux and Mac OS use ps -A | grep node to find node process ids. Once a process is started, you can also attach the inspector by sending signal to the node process SIGUSR1 Reference

The node-inspect program (source) is separate from core node. Though it is bundled with nodejs. Node inspect reimplements node debug to address a limitation

For Chrome inspector protocol, there's only one: node --inspect ... This project tries to provide the missing second option by re-implementing node debug against the new protocol.

Debugger API documenation

Additional Ways to Attach Debugger

https://nodejs.org/en/docs/guides/debugging-getting-started/

You can view an interact with the debugger in Chrome. Just add additional connections under the Connections tab of the dedicated NodeJS DevTools window.

Chrome Window for DevTools connections

Similar, but Separate, Projects

Worth noting there is a similar project, now deprecated, that is called node-inspector, which is separate from node-inspect Tested October, 2018 with node v10.11.0


As mentionned https://stackoverflow.com/a/18911247/1301197 you can specify a port with

node --inspect=7000 --inspect-brk app1.js

Then of course you just to specify a different port for each node server

node --inspect=7001 --inspect-brk app2.js

Update: If you are reading this in 2019, the below answer is out of date. You'd probably want to check out the current documentation or follow gtzilla answer: https://nodejs.org/en/docs/guides/debugging-getting-started/

First, start your node programs with different debug ports like so:

$ node script1.js --debug==5858
$ node script2.js --debug==5859

Then start node-inspector

$ node-inspector &

and open the web console in two tabs with

  1. http://localhost:8080/debug?port=5858
  2. http://localhost:8080/debug?port=5859