Node.js, node-inspector, JavaScript, Google Chrome: debug workflow - javascript

I start a debug session like this:
$ node-debug -p 8082 try-debug.js 8081
Then I go to the Node Inspector tab in Google Chrome. Unfortunately, I can't figure out how to abort the debug session and/or reload modified source short of restarting manually the node-debug server and reloading the Node Inspector tab.
What is the right way?

Related

How do I debug server and client simultaneously in WebStorm?

I have a node.js app that runs a server and sends index.html. The index.html interacts with the server.
I want to debug the complete app, but when I debug the app, WebStorm only debugs the server.
Is this even possible in WebStorm? If not, are there other tools that can do this?
In the Node.js run configuration, Browser/Live Edit tab, specify the URL of your server, tick both After launch and with JavaScript debugger checkboxes - client-side debugger will be launched once you start your node server with this configuration, so that you will be able to debug both simultaneously, using a single run configuration.
See also https://www.jetbrains.com/help/webstorm/debugging-javascript-in-chrome.html#debugging_js_on_external_web_server for some hints on debugging client-side code run in browser

sending console JS commands to an Electron app

I'm looking to automate an existing Electron app. It gives access to the Developer Tools, so I could just paste Javascript code into the console, but there must be a way to do this remotely, ideally using Node or from the Terminal?
I've seen this option for running Chrome : --remote-debugging-port=9222 ... that hints at a solution but I can't seem to get closer.
If you launch your Electron app with --remote-debugging-port=9222 then you will enable remote debugging via Chrome DevTools protocol. You can use a Chrome developer tools instance as a client, or use one of the clients here: https://github.com/ChromeDevTools/awesome-chrome-devtools#chrome-devtools-protocol
The debuggable Chrome instance will be running on localhost:9222. Which means as long as you are trying to debug from the same machine you are fine. However if you want to debug from a remote machine you need some additional setup.
Setup an SSH tunnel on the source machine:
ssh -L 0.0.0.0:9223:localhost:9222 localhost -N
This will accept incoming traffic on the 9223 port and route it to Chrome remote debugging.
Then on your client machine use the address: source-machine-ip:9223 to access the remote debugging.
Note: This may not work on Windows without additional SSH setup as SSH is not prepackaged with Windows.

Can't get node-debug to work

This feels really silly, but I can't get node inspector / node-debug to work.
The instructions say to do npm install then to run node-debug web.js. So I did that. Now I have a lovely browser window open showing me my code with breakpoints... and no idea which url to use to actually access the code.
The inspector is at http://localhost:8080/debug?port=5858 and the terminal says:
> node-debug web.js
debugger listening on port 5858
Node Inspector is now available from http://localhost:8080/debug?port=5858
Debugging `web.js`
...
I've tried hitting up localhost:5000 (which is my express.js port) but that either fails if I don't have a separate node web.js instance running, or it succeeds if I have the other one running but doesn't trip any of the breakpoints in the inspector.
When I go to http://localhost:5858/, I get:
Remote debugging session already active
When I go to http://localhost:8080/, I get:
Cannot GET /
(the / path totally works on my server in general.)
By default node-debug starts app in --debug-brk mode.
This stops your app at first line (express not started).
You can use node-debug --no-debug-brk see the node-debug --h for more info.
Agh. Okay, looked at some more questions before I got this posted. Looks like the problem was just that I wasn't running the original instance in debug mode. Nobody had told me I had to, so I just didn't know otherwise!
What's working for me now:
> node debug web
then in a different terminal
> node-debug web.js

Webstorm debugger for node.js

I'm trying to configure Webstorm for using the node.js' debugger.
I've set the enviroment and everything, the app is running fine with the run button, but with the debugger button it just hangs up writing only:
/usr/bin/node --debug-brk=52006 --debug-brk node.js
debugger listening on port 52006
and it doesn't work or writes anything on the output.
Any idea of what is missing? I've already installed node-inspector and everything.
EDIT:
After sometime that I run the code, I get:
Failed to open socket on port 52708, waiting 1000 ms before retrying
Problem solved with the help of JetBrains. In a few words, I used cluster creating child nodes that weren't connected to the debugger.
Full explanation here: https://intellij-support.jetbrains.com/tickets/13630

No targets shown in WEINRE (Cordova/PhoneGap)

I've been trying to connect my device to weinre, yet I cannot see any target device in it.
This are the steps I'm following:
Creating project in Cordova
Adding android platform to the project
Adding the weinre script to my project's index.html
Initiating weinre server in my computer
Pinging both devices IP from each other to ensure they can see each other over the network
Opening weinre server in my chrome browser
Running my App
No target ever appear
Please if I'm doing something wrong tell me, but can't see, to connect any target itno my weinre server.
Best regards.

Categories

Resources