Debugging in WebStorm for node.js - node.js

I recently joined the team which uses the node.js for the development. I am new to the whole node.js ride. I have used IntelliJ based IDEs in the past to configure to run and debug different programming languages. However lack of my understanding of node.js or for some other reason I cannot debug node.js application currently I am working on.
Using node v0.10.48, npm 2.15.1
I can run the application using the WebStorm IDE, but when I run the application, following is what I get in the console tab of debug panel. It also returns a > prompt in the console.
/usr/bin/node --debug-brk=44917 --expose_debug_as=v8debug <path_to_startup_js_file?
debugger listening on port 44917
debugger listening on port 44918
It stops for the break points that I put in the beginning of the file, but after starting the server nothing happens. Now I can't open client UI application, which makes calls to this node.js/express REST service. Even though it is up and running, I think.
By the way I know how to debug using node-inspector & browser. But not sure what am I doing wrong with IDE. The run profile works fine, but the same profile is not working for debug.

It turned out that application I was working on was spawning child process, which has to be debugged separately as a remote debugger. Webstorm was nice enough to support debugging both master and child thread at the same time, via two separate debugger.
The current node version used by the project is also relatively old. Which was also the part of the issue with the webstorm. It was verified by the jetbrain support team member.

Related

What is best and simple way to debug Node.js on simple task

Simpel task: like Express app or CLI app on local machine
After I try node-inspector and that not work very well by now .
and the debugger of webStorm stop working properly for me.
and visual studio code work some time but the debugger not mature enough like chrome dev tool
what is the best way to debuuger node.js 6.x.x.this day ?
Usually these are private preferences but you can use the V8 from the Chrome Developer Tools to debug Node.js.
on chrome : go to chrome://inspect and click Open dedicated DevTools for Node
New windows openning for you and waiting for node application to connect
then in terminal write :
node --inspect app.js
and that all. the debugger windows attach automatically to the app for debugging. and every time you reset the app debugger windows attach again automatically
have fun

Best way to debug Node.js application in IntelliJ or WebStorm

I see a lot of posts how to debug posts and talks on how debug node application and they mostly points to vs code and other command line tools.
As a fan of IntelliJ and WebStorm IDE, is anything I am missing which can save my day while debugging my Node.js application?
Please see https://blog.jetbrains.com/webstorm/2014/05/guide-to-node-js-development-with-webstorm/ - this post is not new, but still relevant
Jetbrains has a write up of how to debug Node.js applications that is a good starting point:
https://www.jetbrains.com/help/idea/running-and-debugging-node-js.html
The biggest issue that I've run into is that none of the provided solutions automatically restart your application when changes are made. I've worked around this by using their remote debug functionality and attaching to a server running with nodemon. However, I still have to manually restart the remote debug job in IntelliJ as it does not automatically reconnect when the remote debug server restarts.
There is an open YouTrack request to add this functionality, but Jetbrain's recommendation is to instead use their Live Edit functionality.
Live Edit is bundled by default with Webstorm, but has to be installed on IntelliJ Ultimate. I have not tried using Live Edit with a Node.js application, but their documentation says that it should work.

Visual Studio Code - Debugging a spawned process

The project setup, is a basic express application, generated with express-generator.
The project, vscode-debugging-node is available at GitHub
Please refer the screencast at Visual studio Code - Debugging node application
The Gruntfile.js in root of the project, manages the dev process. The purpose of the Gruntfile.js is simple, it starts the server and watches for any file changes.
On detecting changes in the desired file(s), it restarts the server (kills the existing process and starts a new one).
The Gruntfile.js uses ./task/server.js to start/restart the server.
The Gruntfile.js is developed in this manner, that later on, it will incorporate cookie management, in order to provide a logged in experience.
While executing the $ grunt start task, if a env variable named NODE_INSPECTOR=* is passed, the server is started in --debug mode.
When the grunt task is executed in --debug mode, along with node-inspector running in parallel, I can use Chrome to debug the complete application.
With reference to Debugging in Visual Studio Code, I tried to achieve the same by updating the .settings/launch.json, with "program": "/usr/local/bin/grunt", "args": ["start"] and "env": {"NODE_INSPECTOR":"*"}.
I could find that debugger is attached only till ./task/server.js but on the whole application. I doubt, it may be due to the spawned server.
Is this possible to debug such situation in visual studio code? If yes, it will be of great help to know the details.
Your doubts are correct, you are configuring Visual Studio Code to attach to the grunt task starting the server, not the server itself.
You have two options to order to debug this:
Execute NODE_INSPECTOR=* grunt start form the terminal.
Once the server has started, attach the the running server to the Debugger, using the same Attach configuration available in launch.json. In the Debugger view choose the Attach from the profile dropdown and start the Debugger (green ► play button).
UPDATE --
Sarbbotam recorded a screencast for successfully attaching to his node.js app, you can find it here Visual studio Code - Attaching a Node App to Debugger
Configure VSCode to run the server directly, for that you won't have the grunt task listening to the changes and restarting the server. In order to do that change the program option to "bin/www"

Trouble debugging nodeJS with nodeclipse (Failed to connect to Standalone V8 VM)

Hoping someone can help. I've been through every forum, the online help, every youtube, and every example to find an answer. This either means it's incredibly nuanced or incredibly simple and I'm just missing something that seems to work for everyone.
Nodeclipse/chromedevtools failed to connect to Standalone V8 VM
( Check Help (F1) and Support http://www.nodeclipse.org/#support )
. Info:
connect timed out
I get the above error when I use nodeclipse to debug a node app using the right-click menu on the project. DEBUG AS -> NODE APPLICATION.
When I RUN AS -> NODE APPLICATION, it launches just fine. But when I run with debug-as, I get that error and the debug info looks like.. (or not.. I can't post images... but it terminates the V8 VM entry)
I've installed JDK 8, the most recent NodeJS, the express packages, enide studio from nodeclipse.org, and followed the instructions to build a starter app (new - express project), then attempted to debug that app with debug-as->node application.
I can successfully debug a node instance (my actual project) that I start from the command line, and it lets me step through the virtual project files, etc.. but I was looking for the "all in one" nature where I am debugging the same files I'm editing and can launch/test it all from within eclipse.
Win 7, 64bit
JDK 1.8.0_11 64bit
node 0.10.29 64bit
nodeclipse/enide studio 2014-011-20140228-win64
I've tried it with JDK1.7 as well (64 bit).
Any and all help would be appreciated.
Regards,
Zig
While the issue happened before it is hard to reproduce on other machines.
More stats is needed.
http://www.nodeclipse.org/#support gives links to Online Help (the same as built-in by F1)
in particular
https://github.com/Nodeclipse/nodeclipse-1/blob/master/org.nodeclipse.help/contents/run.md
and https://github.com/Nodeclipse/nodeclipse-1/blob/master/org.nodeclipse.help/contents/debug.md
Have you tried to
to run node --debug-brk app.js first, and then again in Eclipse/Enide Studio ? #107
I've had some luck getting around this error by:
Right clicking in the server and selecting run as -> node application
Navigating in Firefox to the address where my server is listening
Stopping the server in the console
Right clicking in the server and selecting debug as -> node application
I also created a new perspective called "visualstudio" and do no switch perspectives between development and debug (though I doubt perspectives have much to do with the issue)
Using this approach, I get an interesting anamoly where the debugger breaks on line 1 when the server starts, and I then have to click resume. However, after resuming, execution only stops when a request hits a breakpoint.
You have to run the command to debug the node.js file:
node --debug-brk yourfilename.js (this is not working now)
node --inspect-brk yourfilename.js

How can I debug my Meteor app using the WebStorm IDE?

Can anyone provide a short list of steps on how to connect a Meteor app to the WebStorm debugger please?
WebStorm is the only IDE with native support for debugging Meteor server code - check this video. Even on Windows, debugging is very simple:
WebStorm 9+
Go to Run --> Debug --> Edit configurations... , click the plus sign, click "Meteor". You can add environment variable like ROOT_URL if you need to.
WebStorm older than 9
This answer is kept only for historical purposes. You should upgrade WebStorm.
On older WebStorms, you used to have to create a Node.js debugging configuration.
on the server, export the environment variable NODE_OPTIONS=--debug=47977. For instance,
NODE_OPTIONS=--debug=47977 meteor # Linux/Mac
set NODE_OPTIONS=--debug=47977 & meteor` # Windows
create a WebStorm/PhpStorm Run/Debug configuration using the port above (47977) and the server host. Leave 127.0.0.1 if you're debugging locally.
in WebStorm, Run -> Debug <myapp>, or press Shift+F9. Make sure that you see "Connected to <your host> in the Debug panel
Now you can set breakpoints, have access to local variables etc.
For client debugging, just use the Chrome debugger, or Firebug.
Troubleshooting
Process disconnected unexpectedly - this happens when meteor restarts automatically because of lack of specific support for Meteor. Just Run -> Debug <myapp>, or press Shift+F9 again.
you can't connect to the server - make sure the firewall rules allow incoming connections to whatever port you chose for the Node.js debugger (47977 here).
The other answers are now out of date. Don't add a Node.js debug configuration as described above, or bother with spyjs.
If you're using Webstorm 9.0, it's as simple as going to Run --> Debug --> Edit configurations... , click the plus, click "Meteor".
WebStorm may also ask you to install a browser add-on, but that's just for client-side debugging; just add a breakpoint in the server-side code and you'll see it works out of the box.
JetBrains have updated the video which was linked to in Dan Dascalescu's answer above, and it shows you the process I just described.
For applications using webpack:webpack, using WebStorm's Meteor debug profile did not seem to work.
My setup uses webpack:webpack v1.0.12, Meteor v1.3.0 and WebStorm 2016.1, but is likely to work with later versions (note that a fix for just this issue was released in v1.0.12, so earlier versions are likely not to work with this procedure).
Here is what I did in order to get it working:
Create a webpack.json file at the project root.
It should include the devtool config, which generates source maps that assist in debugging. The rest may be changed according to your specific setup.
{
"root": "src",
"devServer": {
"host": "localhost"
},
"devtool": "source-map"
}
Create a debug setup:
Node.js Remote Debug, port 5858 (the port is configurable).
Run meteor debug
You may specify a port using --debug-port <port number>.
See meteor help debug for the full details.
Connect WebStorm to the debugger
start the debugger
the status message should indicate that it is connected. Scripts should available in the Scripts tab.
the server should be running in the console
Hit your breakpoints and rejoice.
WebStorm 9 will have Meteor support. While WS 9 isn't released yet (as of Oct 7, 2014), there is an early access program for WS 9.
Read the JetBrains WebStorm blog which describes some of the Meteor support features and includes a brief video.
I'm new to Meteor, WebStorm (and JavaScript for that matter) and have been using the WS 9 EAP build 138.2406 for a couple of weeks. I can launch my project from within the IDE, set breakpoints, walk though code, inspect values, jump to definitions, and issue completions. It's quite helpful.
You can try spyjs plugin for Webstorm: http://blog.jetbrains.com/webstorm/2014/04/spy-js-webstorm-secret-service/
There is a bug with old versions of Webstorm to debug server-side of Meteor 1.2.x. The latest version of Webstorm (11.0.3) released on Dec 24th, 2015 fixed it. Release notes can be found here: https://confluence.jetbrains.com/display/WI/WebStorm+143.1559.5+Release+Notes
I am now able to debug without any problem from Webstorm :)

Resources