I'm remote debugging a node.js process via WebStorm (running on MacOS 10.12.6).
I'm attaching to the process successfully (I know this because I run node with --debug-brk and then the process suspends until I resume it in WebStorm), however there is no indication that the breakpoints are attached (of course they also don't work - the code in the breakpoint line is running but the breakpoint isn't suspending the process).
Few notes:
The breakpoint is enabled and "Suspend" is checked.
Local debugging works fine
Don't know if it's related by I tried to switch this registry: js.debugger.v8.use.any.breakpoint on/off and there was no change.
This is the command I use to run the node:
node --debug-brk=5858 server.js
Anybody has an idea?
Related
How is Visual Studio Code debugger able to attach to a already running node process?
I simply used npm start to run my node application and then use the VS Code "attach to process Id" launch configuration to start the debugger. I didn't had to start my application with --inspect or --debug flag. How is this actually working?
As can be found in the nodejs docs:
Node.js will also start listening for debugging messages if it receives a SIGUSR1 signal. (SIGUSR1 is not available on Windows.) In Node.js 7 and earlier, this activates the legacy Debugger API. In Node.js 8 and later, it will activate the Inspector API.
VS Code sends SIGUSR1 to the process. From the VS Code docs:
the debugger tries to attach to this process after having sent a USR1
signal. With this setting, the debugger can attach to an already
running process that was not started in debug mode.
I'm trying to set up a run configuration to start Javascript debug & debug of my frontend at the same time. It is possible to start both debug sessions manually and it works. But I have to do this after every change.
It would be nice to have them both restarted in debug mode. I can set the server to run before the js debug in the run config, but this waits until the server is stopped to start the js debug.
I also tried to set an npm config. This works because I use pm2 to start the server in background, but not in debug mode.
Thanks for your Help
If you are using Node.js run configuration to start your server, you can use Browser/Live Edit tab to start client-side debugging on starting your server: just specify your application URL there and check both After launch and with JavaScript debugger options
If you start your server with NPM script, your only option is using the Multirun plugin for running both npm start and JavaScript Debug run configurations concurrently
I am following the directions here: https://github.com/node-inspector/node-inspector
Pretty simple. npm install node-inspector. In one shell run node-inspector and in another run node --debug app.js. Shell spits out an localhost address with specific port for the debugger. Open that address in a browser — it loads your code. From there add breakpoints, debug network, etc..
But this does not work.
The following message endlessly logs in my shell:
Failed to open socket on port 5858, waiting 1000 ms before retrying
..and no connection is made.
So my question is has anyone had this problem and successfully found a solution. Would love to get this working, would be super useful. My only experience in server-side debuggers is Ruby's Byebug which was a piece of cake to set up.
The message you see is printed because there is another process listening on port 5858. Either a different application, or simply another instance of a node process under the debugger.
An update based on comments below this answer
If your application is running in a cluster mode via Node.js core module "cluster", then you end up with multiple worker processes, where each of them is trying to listen on port 5858.
Node Inspector cannot debug multiple worker processes at the same time. You have to pick one process and enable the debugger in that process only. When you start the app via node --debug, all processes try to enable the debugger, therefore you cannot use this command.
Instead, you have to:
Start your app without the debugger enabled.
Then you need to find the pid (process id) of the worker process you would like to debug.
Once you have the PID, you need to enable the debugger in the target process. You can run kill -1 <pid> on UNIX, or use node debug -p <pid> that works on all platforms. Don't forget to exit node debug before proceeding further.
Once the target process has debugger listening on 5858, you can start Node Inspector the usual way.
My answer is based on the following blog post: https://strongloop.com/strongblog/whats-new-nodejs-v0-12-debugging-clusters/, check it out for more details.
I am trying to debug a very simple script using "node-inspector".
I tried both following instructions on the repo, which include running "node-debug" and instructions here which include running "node --debug-brk yourApp.js".
The main problem is that neither of the commands "node", "node-debug" or "node-inspector" return any result. They just return silently.
Running "nodejs --debug-brk myScript.js" on the other hand works, but does not seem to have a nice debug GUI. I can connect to it on http://127.0.0.1:5858/ but it is hardly useful for variable inspection.
Once you've installed node-inspector globally (with npm install -g node-inspector) you can use it to connect to a nodejs process that's been run in debug mode. Try the following steps.
Open two terminal windows
In the first, run your process you'd like to debug with node --debug-brk myscript.js
In the second, run node inspector with node-inspector
In Chrome, visit the following address: http://localhost:8080/debug?port=5858
What you've done here is start node in debug mode (at port 5858 by default), then launch node inspector, which runs its own webserver on port 8080. The URL (the debug?port=5858 part) is telling node-inspector to connect to the node debug process that's on port 5858. Once you're in there, you'll see that your process has stopped on the first line (as instructed to by --debug-brk). You can then set any other breakpoints you'd like, then press the "play" button to start your process running!
I'm trying to debug my nodejs app using node-inspector. But Google Chrome doesn't show the code.
I'm using the following,
Node.js : v0.10.26
Express : 4.0.0
Node Inspector : v0.7.3
Google Chrome version : 34.0.1847.131
This is what I'm doing to start the debugger..
$ node-inspector
Node Inspector v0.7.3
Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.
In another console,
$ node --debug app.js
debugger listening on port 5858
$
Then started Google Chrome and went to
http://127.0.0.1:8080/debug?port=5858
It opens up node-inspector but without any code..all windows are empty.
Noticed that I'm not getting 'Express server listening on port 3000'
Tried all as per node-inspector fails to connect to node but no luck
Couldn't work out what I'm missing. Would be great of you have any suggestions..so I can debug my Node.js apps in Google Chrome.
Try to run node --debug-brk app.js instead of just --debug. Your application may not be pausing before node inspector hooks into the node process. Using --debug-brk will force node to break on the first line of your app and wait for a debugger to attach to the process. Loading the node-inspector web interface is what causes node-inspector to attach to your node process; that's why you include the node debug port in the query string (localhost:8080/debug?port=5858). You're telling node-inspector what port it should reach out and attach to.
Here's an animated gif I put together showing a complete install and run of node-inspector.
In the gif I use the --debug flag because I'm not debugging any code that runs right at startup. I'm debugging inside a request handler, which only fires when the page is requested. Thus, refreshing the page causes node-inspector to break on that line.
I also put together a 15 minute YouTube tutorial a while ago.
http://youtu.be/03qGA-GJXjI
node-inspector by default tries to pre-load all the code before initiating the debug window. I have had instances, node-inspector just hangs for ever because of this pre-loading. Luckily the newer versions have an option to stop the pre-load thereby making the inspector load faster.
Try node-inspector --no-preload
Standard remote debugging is broken entirely in node 6.5. It's replaced however by a new internal node feature
$ node --inspect --debug-brk build/server/server.js
Debugger listening on port 9229.
Warning: This is an experimental feature and could change at any time.
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/remote/serve_file/#62cd277117e6f8ec53e31b1be58290a6f7ab42ef/inspector.html?experiments=true&v8only=true&ws=localhost:9229/node
Debugger attached.
See here - http://arveknudsen.com/?p=346%3Fpage_id%3D346&print=pdf - for more info
--debug-brk is now deprecated
try node --inspect-brk <your starting file name>
and then go to chrome and type url
chrome://inspect and click on Open dedicated DevTools for Node,
the debugger will start, no need of node-inspector
On the left of Node Inspector, "Sources" tab, there is "a box with a triangle in it" - highlighting says "Show Navigator". (See it in the picture above). Open that to find the files you want to debug, and put a break point on code that has yet to run.
Also note, if you want to debug code that runs on starting node, you'll need to use the --debug-brk option when starting. Then, in Node Inspector, you you'll have to kick off the app (F8 to run all). You'll need this option if you want to debug all the initialization code, like starting a web browser.
node-debug --no-preload app.js
This what's working for me. Accoriding to this:
My script runs too fast to attach the debugger.
The debugged process must be started with --debug-brk, this way the
script is paused on the first line.
Note: node-debug adds this option for you by default.