WebStorm: node.js debugger vs remote node.js - node.js

I've encountered two debugging configurations for node.js in WebStorm:
Node.JS debug and node.js Remote Debug. You can see both of them here:
My question is what is the difference between these two? and when should we use each one of them?

With Remote Debug configuration, you can attach the debugger to already running Node application started with --debug-brk. See https://www.jetbrains.com/help/webstorm/2016.3/running-and-debugging-node-js.html#remote_debugging, https://confluence.jetbrains.com/display/WI/Running+and+debugging+Node.js+application#RunninganddebuggingNode.jsapplication-DebuggingNode.jsappthatrunsremotely
With Node.js run configuration, you can start the Node.js interpreter (either local or remote) and pass your application to it.

Related

Remote debugging nodejs app in Intellij with Docker - port already allocated

I want to start debugging node.js app using Intellij and node.js interpreter running on Docker. While running the app works, when I try to debug I get the error:
Error running 'index.js'
com.github.dockerjava.api.exception.InternalServerErrorException:
{"message":"driver failed programming external connectivity on
endpoint focused_poincare
(a17137973880d1be7c6a74fc142184fdda31e0dec8ebd539b09d9dbe4cf70014):
Error starting userland proxy: Bind for 0.0.0.0:55578 failed: port is
already allocated"}
Remote interpreter was configured acccording to the documentation. I have created a new Node.js Run/Debug configuration and entered the following data:
.
What might be the cause for debugging not working?
I use:
Intellij Idea Ultimate v. 2019.1.4 Preview
Intellij NodeJS plugin v. 191.7479.1, NodeJS remote interpreter plugin v. 191.6014.8 and Docker plugin v. 191.7141.44
Docker Desktop Community v. 2.0.0.3
EDIT: Adressing the comments:
Local debugging works. The file (index.js) that I am trying to run consists only of console.log('Hello world!') so I don't spawn any child processes on my own. My host system has Windows 10 Pro as OS, so for checking the open ports on host system I used netstat -an | find "55578", which returned nothing. Moreover, if I try to run docker manually from the command line, using docker run -it -p 55578:55578 node, everything runs and no error is given.
Also, each time I try remote debugging, the port number given by Intellij in an error message seems to be random high port number. I tried looking for open ports just after getting error message, but never found one that is open with a number reported by Intellij and those indeed appear in the output:
My Run/Debug configuration:
My Docker configuration (I had to check "Expose daemon on tcp://localhost:2375 without TLS" in Docker configuration to make Intellij and Docker play together):
EDIT: When I add --inspect-brk=0.0.0.0:55432 as "Node Parameters" in "Run/Debug Configurations" Intellij windows (per this bug report) the container nad program start, but debugging seems to be no-op (e.g. the program does not stop on breakpoints).
After updating to Intellij v. 2019.2 I was able to get the container debugging to work using the workaround already mentioned in my question.
I have added a parameter --inspect-brk=0.0.0.0:55432 to Node parameters option in Run/Debug configuration (see the picture below) and everything seems to be working, including the breakpoints.

How to debug a node app from WebStorm?

I am running node --inspect app.js inside of a docker container.
In the console I see Debugger listening on ws://127.0.0.1:9229/0b4d64ac-90c1-480d-a98a-7061c0b49189
How can I debug using WebStorm? I know on a previous version of node there was --debug I would then connect using the Node.js Remote Debugger.
To attach to remote Node.js app started with --inspect/--inspect-brk, (Node.js 7+), you need using Chromium Remote run configuration.
See also https://blog.jetbrains.com/webstorm/2017/09/debugging-node-js-apps-in-webstorm/, https://www.jetbrains.com/help/webstorm/running-and-debugging-node-js.html#node_docker_run_debug

Debugging Node with Chrome Dev Tools: "Debugging session was closed" and other issues

tl;dr: Getting "Debugging connection was closed. Reason: websocket_closed.
" when trying to debug using Chrome Dev Tools with Node.
I want to do some code-stepping of a Node app. I thought I'd give Chrome Dev Tools a try.
I'm having a few issues that are preventing me from using CDT, and I'd appreciate any help.
1) When I do the following commands in Terminal
node --inspect myFile.js
or
nodemon --inspect myFile.js
the server seems to start fine, but when I pull up the CDT Node tools through
about://inspect
nothing appears in the CDT Node debugger, no sources, nada. If instead I access the tools by pasting in the URL that the above commands produce in the terminal into Chrome -- something like
chrome-devtools://devtools/remote/serve_file/#521e5b7/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node
I get in the CDT Node debugger an announcement
Debugging connection was closed. Reason: websocket_closed.
What gives?
2) When I add the flag "--debug-brk" thusly
node --inspect --debug-brk
the server doesn't even start normally.
I'm using MacOS 10.12.4, Node v6.3.1. The server is running on port 9999, there is a client app that hits the server on that port, the client app runs on port 4200. I'm trying to debug the server code here.
(By the way, if you have another better tool than CDT to recommend for debugging Node I'd be keen to hear of it -- I have WebStorm but the process to debug Node seemed more complicated than that for CDT.)
Any help much appreciated --
Perhaps it was the weather? : following the same procedures as before, same code, I've gotten the CDT to work with the app I wanted to debug. The warning
Debugging connection was closed. Reason: websocket_closed.
was signaling that the app had stopped and thus there was no connection open.

What's the best way to debug a NodeJs app running on a docker container in a remote host?

I have a NodeJs app running on a docker container on a remote server. I can access the app on the browser. I'm also able to deploy to my app using PhpStorm and its remote server connection.
However, I tried to use the remote NodeJs debug tool of PhpStorm and it doesn't work. I always get connection refused.
I know the debug port is open because I check the docker containers and the 5858 is open. This port is also oppened on the host. And this is also the port I set for the debug.
package.json:
"scripts": {
"start": "nodemon --debug=5858 index.js myApp"
}
I don't know if PhpStorm is the best solution to debug this kind of app. So if someone has a better idea please let me know.
Thanks!
After further searching I found this great repository:
https://github.com/seelio/node-inspector-docker
It seems to me the easier way to make the app running and debug it.
Definitely node-inspector,
I had to do the same for an app in microservices and clusters/workers
just in case you need it: clustered apps with node-inspector
You can use intelij IDEA as IDE
It support running app directly from docker and allows you to debug apps easily.
once configured with your docker image its done.
next time just click run and it will start quickly nodejs inside your docker and show logs etc all just like we do with local node instance
https://www.jetbrains.com/help/idea/2016.3/running-and-debugging-node-js.html#node_docker_run_debug
Its EAP and communitiy editions are always is free

How to debug two node applications at same time using node's built-in debugger?

I debug my node applications by executing node debug app in my application folder.However if i want to use the same with other application at same time it shows me error.
How can i use debug with the other application too?
Node's default debug port is being used by the first process. Start your second app specifying another port using the --debug-brk or the --debug flag like this:
node --debug-brk=5859 app.js
Then open another terminal window and connect to the second process's debugging port using:
node debug localhost:5859

Resources