Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Node Inspector with multiple node processes

I started using Node Inspector to debug some of my Node applications. However, one thing i am not sure how to do is, once Node-inspector is attached to one Node app, how to detach and attach it to another Node app running on same box?

How can I debug multiple processes at the same time?

like image 447
nodeuser Avatar asked Oct 19 '12 05:10

nodeuser


3 Answers

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
like image 92
Chris Avatar answered Oct 16 '22 19:10

Chris


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
like image 31
Ronan Quillevere Avatar answered Oct 16 '22 20:10

Ronan Quillevere


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

like image 3
gtzilla Avatar answered Oct 16 '22 19:10

gtzilla