How can I make node-inspector restart when node is restarted?
Step1. don't use node-inspector
- new work has been shipped by chrome team, which can't be integrated with node-inspector module. Moving forward you gonna miss those features if you stay with node-inspector
.
Step2. To run your script use: nodemon --inspect-brk yourScript.js
- the brk part creates an automatic break-point on the first line of code. If you don't have nodemon already installed, you do that first using: npm install -g nodemon
.
Step3. Then open chrome app, open chrome dev tools (F12
or Ctrl+Shift+I
) and click the node icon like so:
Step4. Make changes to yourScript.js
- chrome devtools automagically reloads the debugger for every change you make in your project. This is because nodemon watches the project folder and resets the process - which resets the debugger connection.
More here: Debugging in 2017 with Node.js - i'm writing this in 29 august 2019 but 2 years later is still relevant.
You don't have to restart the Node Inspector process itself when the debugged process was restarted. All you need to do is reload the browser tab with Node Inspector GUI.
I am afraid there is no easy way at the moment for automatically reloading the Node Inspector GUI page when your debugged process is restarted. It is probably possible to perform some kind of active polling in Node Inspector backend, but that's a feature that would have to be implemented by somebody.
Depending on what part of your application you are debugging, you might find useful the feature "Live Edit". It allows you to edit your code from Node Inspector, save the changes to the Node/V8 runtime and possibly back to disk too. That way you don't have to restart the debugged process after you made your changes.
This feature has been implemented in Node Inspector and released in v0.7.0. See issue #266 for more details.
This feature has been implemented in Node Inspector and released in v0.7.0. See issue #266 for more details.
Previous answer here's a workaround:
I wrote a simple js script to be executed by greasemonkey/tampermonkey.
The script looks for the message "Detached from the target" on tab with address http://127.0.0.1:8080/debug?port=5858
. Once the message is visible the page reloads until it disappears.
This solution is a workaround. It shouldn't be considered the ideal solution (I agree with Miroslav), here follows:
// ==UserScript==
// @name Reload node-inspector tab
// @version 0.1
// @description looks for the detached message and auto reload the page
// @match http://127.0.0.1:8080/debug?port=5858
// ==/UserScript==
var exec = function(){
setTimeout(function(){
var el = document.getElementsByClassName("help-window-title")[0];
if(el && el.innerHTML == "Detached from the target"){
location.reload();
} else {
setTimeout(function(){ exec(); }, 1000);
}
}, 1000);
};
exec();
Cross-posting slightly from this SO, with an update to this topic.
There is a link in Chrome (58) standard Developer Pane which opens a new "headless" window which reconnects magically to node inspect no matter how the app is rebuilt / restarted.
I'm running Express.js e.g. DEBUG=myapp:* supervisor -- --inspect bin/www &
and found it difficult to reconnect using the normal guid-laden URL which keeps changing. But this Chrome tool works all day reconnecting reliably.
Under Threads > Main, you should see "Node instance available. Connect".
I find the new-window less usable as I'd prefer a tab, but the auto-reconnect is so reliable I'll live with that!
The only downside I've found is when it does reconnect it clears all breakpoints.