Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make node-inspector restart when node is restarted?

I use node-inspector a lot. When I edit my code and restart, I get the inevitable

Detached from the target

Error when a new process starts. I always have to go find the tab node inspector is on and restart it.

I was wondering if I could avoid this. For example, send a message to node-inspector from node to tell the browsers tab running node-inspector to restart.

like image 526
mikemaccana Avatar asked Sep 17 '13 15:09

mikemaccana


People also ask

How do I restart node server automatically?

Running non-Node code While Nodemon is running, we can manually restart our application. So instead of stopping and restarting Nodemon, we can just type rs and press enter, and Nodemon will restart the server or the running process for us.

Does node require restart?

This is a quick tip for using nodemon to monitor your JavaScript files for any change. While doing development on any NodeJS application, whenever we make any change to some file we need to restart our Node server from the command prompt/terminal.

How do I restart a node project?

If it's just running (not a daemon) then just use Ctrl-C .


2 Answers

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.

like image 61
Miroslav Bajtoš Avatar answered Oct 12 '22 16:10

Miroslav Bajtoš


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();
like image 32
pmariano Avatar answered Oct 12 '22 16:10

pmariano