how to debug Mocha when it continually opens new Debugggers - node.js

I keep having this issue where Mocha opens multiple debuggers when I run mocha --inspect-brk. Even though Chrome easily attaches its Node inspector to the first debugger process, it never attaches to the second process that Mocha starts up and Mocha just hangs forever.
How do I get Chrome to continue to attach inspectors to all the processes that Mocha starts up?
For example, I run mocha --inspect-brk and get the following output printed to my terminal:
Debugger listening on ws://127.0.0.1:9229/xxxx
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Debugger listening on ws://127.0.0.1:43210/xxxx
While Chrome attaches easily to 127.0.0.1:9229 (which you can see in the logs above with Debugger attached), it does not attach to 127.0.0.1:43210.

This happens when Mocha opens processes with debuggers that use ports which Chrome's Node inspector does not know about yet. In the example, 43210 is the port which Chrome isn't trying to attach debuggers to.
Here's how to solve this:
run mocha --inspect-brk
copy the host of websocket URL that never gets a debugger attached to it (in the given example, this would be 127.0.0.1:43210)
open Chrome
go to chrome://inspect/#devices in Chrome
click Open dedicated DevTools for Node
open the Connection tab (next to the Console tab) in the new window that pops up
click Add connection
paste in the copied host name (from step 2) to Chrome for the new connection
Now Chrome will connect an inspector to the new process! If any other port numbers are used in subsequent processes that Chrome doesn't connect to, simply add those to Chrome's Node inspection connection list as well.

Related

Connecting to netlify on localhost with chrome and firefox

I am trying to follow this tutorial.
At 55:39 Ania is able to connect to her localhost:8888/.netlify port to see the records she has read from the graphql playground.
I am trying to do the same but cannot connect to the page. I have tried in both chrome and firefox and in both cases, I get a connection refused error message.
My firewall has permitted access for both chrome and firefox, and I even tried disabling the firewall. The error still returns.
I tried it without my vpn turned on.
I have logged into netlify (I have nothing on github yet, so it's just a local deployment).
Is there something special I need to do to be able to run local host with netlify?
The full text of the error message is:
This site can’t be reachedlocalhost refused to connect. Try:
Checking the connection Checking the proxy and the firewall
ERR_CONNECTION_REFUSED Check your Internet connection Check any cables
and reboot any routers, modems or other network devices you may be
using. Allow Chrome to access the network in your firewall or
antivirus settings. If it is already listed as a program allowed to
access the network, try removing it from the list and adding it again.
If you use a proxy server… Check your proxy settings or contact your
network administrator to make sure that the proxy server is working.
If you don't believe you should be using a proxy server: Go to
Applications > System Preferences > Network > Advanced > Proxies and
deselect any proxies that have been selected.
In relation to #1, I am connected to the internet. I can run the local host on port 3000 and get the react app to load. it does not read anything from graphql. When I console log the datastax data from the react app, I get null as a result (where Ania gets the records created in the first hour of the tutorial).
In relation to #2, chrome and firefox are both added to my firewall
In relation to #3, no proxies are used - except the box to use FTP Mode PASV is checked. I tried unchecking it but it makes no difference.
I tried adding the local host 8888 url as a Bypass proxy settings for these Hosts & Domains in my system preferences - but it makes no difference.
My console shows:
◈ Netlify Dev ◈ ◈ Ignored general context env var: LANG (defined in
process) ◈ Injected .env file env var: ASTRA_GRAPHQL_ENDPOINT ◈
Injected .env file env var: ASTRA_DB_APPLICATION_TOKEN ◈ Loaded
function getGenres
http://localhost:8888/.netlify/functions/getGenres. ◈ Functions server
is listening on 55302 ◈ Starting Netlify Dev with Create React App $
react-scripts start (node:55384)
[DEP_WEBPACK_DEV_SERVER_ON_AFTER_SETUP_MIDDLEWARE] DeprecationWarning:
'onAfterSetupMiddleware' option is deprecated. Please use the
'setupMiddlewares' option. (Use node --trace-deprecation ... to show
where the warning was created) (node:55384)
[DEP_WEBPACK_DEV_SERVER_ON_BEFORE_SETUP_MIDDLEWARE]
DeprecationWarning: 'onBeforeSetupMiddleware' option is deprecated.
Please use the 'setupMiddlewares' option. Starting the development
server...
Compiled successfully!
You can now view nextflix-datastax-clone in the browser.
Local: http://localhost:3000 On Your Network:
http://10.0.0.1:3000
Note that the development build is not optimized. To create a
production build, use yarn build.
webpack compiled successfully
ONE CLUE: I have cleaned my mac, I have cleared my cache (don't know why this would have worked since localhost 3000 loads the react app, but without the datastax data). A little box appears on my mac that says 'verifying AID.dylib'. I understand dylib means a shared database (maybe this some sort of Datastax reference? The process has been running almost 48 hours and the progress bar is at about 10%. Whatever that program is, it hasn't been verified. I wonder if this is why I can't load localhost:8888/.netifly in the same way that Ania can?
ANOTHER CLUE: I just found this post: https://github.com/netlify/cli/issues/3617 which suggests that Netlify can't read functions in v17. I don't know if that's still current. I'm currently stuck in my efforts to check if this is the source of the problem because my brew commands wont run in my terminal. I think this may be because of some incompatibility with the macOS Monteray upgrade that I just installed. I will update this post if I find a way to configure my computer to be able to follow a basic beginner's tutorial.

TestCafe - Error : Cannot establish one or more browser connections

Testcafe was able to connect browser and trigger test cases before. All of sudden, it stopped working. The main issue is test cafe is able to open browser but it's not connecting to browser and unable to hit URL. Browser is getting opened and being closed by itself after some time. Browser shows following message.
This site can’t be reached XXX.XXX.X.XX took too long to respond.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_TIMED_OUT
I didn't make any changes to softwares except changing my machine's login password. I changed the password in all required places like .npmrc etc.
Appreciate your help if anyone can provide solution.
Software versions:
node -v
v14.17.5
npm -v
7.20.5
testcafe -v
Using locally installed version of TestCafe.
1.15.2
command to trigger my tests : testcafe chrome test.js
Note: This issue happening for all browsers.
Error : ERROR Cannot establish one or more browser connections.
1 of 1 browser connections have not been established:
chrome
Hints:
Increase the value of the "browserInitTimeout" option if it is too low (currently: 2 minutes for local browsers and 6 minutes for remote browsers). This option determines how long TestCafe waits for browsers to be ready.
The error can also be caused by network issues or remote device failure. Make sure that your network connection is stable and you can reach the remote device.
Check permissions, owner and group in /tmp/Crashpad

How to debug Node.js app inside goormIDE with Chrome DevTools?

In my local machine, I can debug my Node.js app with Chrome DevTools.
Since using goormIDE I have no idea how to debug it in the same way.
Is there a way to do that?
In goormIDE, run your Node.js app with option --inspect=0.0.0.0:9229
For example, node --inspect=0.0.0.0:9229 app.js
0.0.0.0 is to allow the connection from DevTools, which is outside of the goormIDE container.
And 9229 is to specify the port that will be using.
Open menu CONTAINER - Port Forwarding Configuration and register a port 9229
Click the copy button at the Command column, then the IP:port value will be copied.
In Chrome, open a new tab and go to chrome://inspect
Enable Discover network targets option and click Configure... at the right.
Paste the IP:port value you copied at step 3, and press Enter then click Done.
Then you may see your app is listed at Remote Target and ready to be inspected.

Debug application with PID in cf

I've node application and I use the following guide to debug it which works great
https://codeburst.io/an-easy-way-to-debug-node-js-apps-in-cloud-foundry-22f559d44516
Now I've a bit more complex scenario which one application is spawn other node application which I want to debug (the spawned application ) , in the cf top I see this app PID (of the spawned app) but my question if there is a way to debug it also ? both app running in the same container .
I was able to debug the master app but not the spawned app..., any idea how ?
I was able to ssh the main app, we are using cf 2.98 version
I don't think there's anything CloudFoundry-specific that needs to be done to make this work. The process described at the link you provided is showing how you can launch an application with the node --inspect flag, create an SSH tunnel to the port where node is listening and then attach to it remotely over the SSH tunnel.
If you're spawning subprocesses, I would suggest that you make sure those subprocesses, assuming they're also running Node, have the --inspect=<port> flag passed to them. In this case, you will need to set a port because the default port 9229 used by --inspect is already taken by your main process.
I don't know if your subprocesses are short or long-lived, but you may need to log the inspect port assigned to them somewhere so that you know which port to connect to so that you inspect a specific subprocess.
Hope that helps!

Debugging with node-inspector: Cannot GET /

I am running a Nodejs server with an application which I want to debug.
In order to achieve this using node-inspector I run the app as follows:
node-debug server.js
Unfortunately I can not access the webserver via URL anymore. Visiting http://127.0.0.1:8080 results in
Cannot GET /
However if I start the application the usual way with
node server.js
everything is fine (except for the fact that I can not debug). But I can access http://127.0.0.1:8080.
The '/' request is also not logged so it seems that it never reaches the server.
Hence the problem I have is: I can access the remote debugger via http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858 but I can not start debugging because I can not trigger any action on the webserver via URL.
Oh and the debugger is not paused or anything. I skipped the first break point.
I resolved the problem by choosing a different port than 8080. It seems like the debugger uses this port. I was not aware of that because this port was familiar to me as I used it for my application.
As Schnodderbalken already answered, the problem lies in the application and inspector both using the same port 8080. If you tell inspector to use a different web port, 8082 for instance, the problem is solved.
You can do this by adding a parameter like so:
node-inspector --web-port=8082
You can then access inspector via http://127.0.0.1:8082/?port=5858

Resources