I have a javascript code that checks whether a point is inside a polygon. I am trying to debug it with node-inspector, following these steps:
In the first window:
PS Z:\dev> node-inspector.cmd
info - socket.io started
visit http://0.0.0.0:8080/debug?port=5858 to start debugging
In the second window:
PS Z:\dev\poc\SDR> node --debug-brk .\IsPointInside.js
debugger listening on port 5858
Now I navigate to http://localhost:8080/debug?port=5858 in my Chrome browser.
What happens is that Chrome gets stuck waiting for localhost presenting me the empty screen.
I must add that I have successfully debugged the r.js javascript optimizer using the same steps before, but now I cannot debug it as well.
according to this there seems to be an order in which the components should be started.
Its application -> debugger -> web browser.
Could be your issue.
You can also send a "debug on demand" command. Use this command:
kill -USR1 $PROCESSID
Related
I'm trying to debug a Node script forked using child_process's fork method using VSCode.
I have read almost all of the related docs, discussions but without any success. I'm not sure what am I doing wrong.
For your reference, I have posted a my sample code as a gist and is available at: https://gist.github.com/dpnishant/43096af3fecde4ec9fdea7c1d81cf543
It contains the three files: parent.js, child.js and launch.json (vscode configuration). I'm trying to setup 2 breakpoints: one at https://gist.github.com/dpnishant/43096af3fecde4ec9fdea7c1d81cf543#file-child-js-L4 and another at https://gist.github.com/dpnishant/43096af3fecde4ec9fdea7c1d81cf543#file-parent-js-L16.
Case-1
When I click "Start Debugging" using the "Launch Program" config, I'm able to hit the line 16 breakpoint on parent.js but the other breakpoint in child.js is never hit.
Case-2
When I click "Start Debugging" using the "Attach" config, I get the following error:
Debugging with legacy protocol because Node.js version could not be determined (Error: connect ECONNREFUSED 127.0.0.1:9999)
Case-3
When I start node parent.js in Terminal and immediately switch to VSCode to click "Start Debugging" using the "Attach to Process" config and choose the node process with the "child.js" script, I'm able to hit breakpoint on line 4 in child.js but by that time, the loop has already started and it's already late.
So my requirement is a method through which I can start my parent.js script and hit the desired breakpoint in child.js as soon as it starts execution.
Can someone point out to me where am I doing wrong? And what would be a optimum solution for my use-case?
I'm following this tutorial Full-stack Redux Tutorial and everything went well till the moment I had to run a local server (Starting under the title "Setting Up a Socket.io Server"). I copied exactly what the tutorial shows and I'm getting this error when running "npm run start"
As seen in the image, the command I'm trying to run is:
babel-node index.js
But the error says nothing I can catch, just that something is wrong with the command, not even with a file.
I'm lost and Google offers little help.
Something else is listening on port 3333 on your machine. Change the port number to something else, and it should work.
If you told us what OS you were using, we could suggest how to determine what is listening on port 3333.
It seems like there's still a connection open on port 3333. If you open cmd and run netstat -a -b you should be able to get a list of open connections together with the executables that started them.
It might be that your Socket.io server previously crashed and the exception wasn't handled properly, possibly leaving the connection open?
I am trying to debug my backend and i am not really sure if i am doing it the correct way.
I have set up the debugging as follows:
Node 6.9.1 and node-inspector 0.12.8
open a command prompt and run the following command:
node-inspector --web-port=3030 (server app port)
open another command prompt and run the following command:
node --inspect --debug-brk server.js
browse to the given URL in the second command prompt log on screen
press F8 to make the server run
eventually put some others breakpoints
browse on another tab to your app (address and port defined in 1-)
see server execution stops on breakpoints defined on step 5.
Now when i run node --inspect app.js and everything looks good so far. I can debug the first start in the app.js. But if I want to debug an endpoint with POSTMAN, I get the error "Cannot POST /api/trainingsWeek". The endpoint works if I don't debug.
Do I have to take another address? Or another tool than POSTMAN?
ANd what is the difference between node --inspect app.js and node-debug
GitHub Issue
UPDATE
This was my stupid mistake :P Here is the solution: https://github.com/node-inspector/node-inspector/issues/907#issuecomment-280620108
I use VS Code to debug. I guess you don't need node-inspector, it will run with the integrated debugger from Node. To get it running, open your project and the debug view. There should be no configuration available. Click on the little wheel -> choose node.js as the environment.
After that the standard json will be created and looks like this:
And then click on the play button with the selection start programm. With that the debugging should run. Now you can use POSTMAN with the same url when you just run your server and the debugger from VS Code should hit your breakpoint.
I'm on node version v5.0.0. I installed node-inspector version: v0.12.5.
what I did:
1st. I start node-insepctor on port 8090 (due to 8080 is taken by nginx)
node-insepctor --web-port=8090
2nd. I start debugging my js file
node --debug-brk app.js
3rd. I open the url in browser
http://127.0.0.1:8090/?ws=127.0.0.1:8090&port=5858
It works for the 1st time, it will perfectly break at the first line. But after I find and fix the issue in my code and I want to debug again, it just can't works again.
What I tried:
1st.
I see that in the console, the following line which printed when I node --debug-brk app.js is still there:
Debugger listening on port 5858
So I refresh the page, the code is shown, but it just doesn't get executed, so no break point is reached.
2nd. I stop the app.js debug process by CTRL-c, and restart debugging app.js, Debugger listening on port 5858 is shown again. so I open the url again. same as above, the code is shown, but nothing happens.
3rd. I stop both the node-inspector process and app.js debug process and restart them both and open the url. this time, it works!!
Is there an easy way to debug a js program more than once??
Every time I need to kill both node-inspector process and debug js process to make it work again??
Or I'm doing something wrong here??
Please help!
node-inspector can be executed with the node-debug <file> command which adds the --debug-brk option by default. This opens the file in the Sources tab and breaks on the first line.
To continue debugging, you'll need to follow the steps below:
Select the file you need to debug from the Sources tab.
Click on a line number of the file to set a breakpoint.
Resume script execution (F8). This will cause the execution to break on the line that was highlighted in step 2.
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.
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();
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.
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.
Sure, it's easy. First install npm install -g nodemon
Then you can run node-inspector & nodemon --debug app.js
(replacing app.js with the name of your script)
Though on syntax error you still may need to reload node-inspector tab manually