Debug JavaScript in WebStorm - javascript

Is it possible to debug JS files from within WebStorm IDE? Preferably, running the app in a Chromium browser instead of using using Chrome developer tools. How do I debug from within WebStorm?

Yes, it's possible. You need to install the "JetBrains IDE Support" add on. Btw: you can run since version 7 Html/JavaScript projects with the builtin webserver.

Since WebStorm 2017.3 you can now use Chrome DevTools and WebStorm debugger at the same time. You no longer need an additional Chrome extension to debug apps in WebStorm.
Read about it in Debugging JavaScript with WebStorm 2017.3

Related

Node JS Application debugging [duplicate]

How do I debug a Node.js server application?
Right now I'm mostly using alert debugging with print statements like this:
sys.puts(sys.inspect(someVariable));
There must be a better way to debug. I know that Google Chrome has a command-line debugger. Is this debugger available for Node.js as well?
node-inspector could save the day! Use it from any browser supporting WebSocket. Breakpoints, profiler, livecoding, etc... It is really awesome.
Install it with:
npm install -g node-inspector
Then run:
node-debug app.js
Debugging
Joyent's Guide
Debugger
Node Inspector
Visual Studio Code
Cloud9
Brackets
Profiling
node --prof ./app.js
node --prof-process ./the-generated-log-file
Heapdumps
node-heapdump with Chrome Developer Tools
Flamegraphs
0x
jam3/devtool then Chrome Developer Tools Flame Charts
Dtrace and StackVis — Only supported on SmartOS
clinicjs
Tracing
Interactive Stack Traces with TraceGL
Logging
Libraries that output debugging information
Caterpillar
Tracer
scribbles
Libraries that enhance stack trace information
Longjohn
Benchmarking
Apache Bench: ab -n 100000 -c 1 http://127.0.0.1:9778/
wrk
Other
Trace
Vantage
Bugger
Google Tracing Framework
Paul Irish's Guide
Legacy
These use to work but are no longer maintained or no longer applicable to modern node versions.
https://github.com/bnoordhuis/node-profiler - replaced by built-in debugging
https://github.com/c4milo/node-webkit-agent - replaced by node inspector
https://nodetime.com/ - defunct
The V8 debugger released as part of the Google Chrome Developer Tools can be used to debug Node.js scripts. A detailed explanation of how this works can be found in the Node.js GitHub wiki.
Node has its own built in GUI debugger as of version 6.3 (using Chrome's DevTools)
Simply pass the inspector flag and you'll be provided with a URL to the inspector:
node --inspect server.js
You can also break on the first line by passing --inspect-brk instead.
Node.js version 0.3.4+ has built-in debugging support.
node debug script.js
Manual: http://nodejs.org/api/debugger.html
Visual Studio Code will be my choice for debugging. No overhead of installing any tools or npm install stuff.
Just set the starting point of your app in package.json and VSCode will automatically create a configuration file inside your solution. It's build on Electron, on which editors like Atom are built.
VS Code gives similar debugging experience as you might have
had in other IDEs like VS, Eclipse, etc.
I personally use JetBrains WebStorm as it's the only JavaScript IDE that I've found which is great for both frontend and backend JavaScript.
It works on multiple OS's and has Node.js debugging built-in (as well as a ton of other stuff](http://www.jetbrains.com/webstorm/features/index.html).
My only 'issues'/wishlist items are were:
It seems to be more resource hungry on Mac than Windows It no longer seems an issue in version 6.
It would be nice if it had Snippet support (like those of Sublime Text 2 - i.e. type 'fun' and tap 'tab' to put in a function. See #WickyNilliams comment below - With Live Templates you also have snippet support.
A lot of great answers here, but I'd like to add my view (based on how my approach evolved)
Debug Logs
Let's face it, we all love a good console.log('Uh oh, if you reached here, you better run.') and sometimes that works great, so if you're reticent to move too far away from it at least add some bling to your logs with Visionmedia's debug.
Interactive Debugging
As handy as console logging can be, to debug professionally you need to roll up your sleeves and get stuck in. Set breakpoints, step through your code, inspect scopes and variables to see what's causing that weird behaviour. As others have mentioned, node-inspector really is the bees-knees. It does everything you can do with the built-in debugger, but using that familiar Chrome DevTools interface.
If, like me, you use Webstorm, then here is a handy guide to debugging from there.
Stack Traces
By default, we can't trace a series of operations across different cycles of the event loop (ticks). To get around this have a look at longjohn (but not in production!).
Memory Leaks
With Node.js we can have a server process expected to stay up for considerable time. What do you do if you think it has sprung some nasty leaks? Use heapdump and Chrome DevTools to compare some snapshots and see what's changing.
For some useful articles, check out
RisingStack - Debugging Node.js Applications
Excellent article by David Mark Clements of nearForm
If you feel like watching a video(s) then
Netflix JS Talks - Debugging Node.js in Production
Interesting video from the tracing working group on tracing and debugging node.js
Really informative 15-minute video on node-inspector
Whatever path you choose, just be sure you understand how you are debugging
It is a painful thing
To look at your own trouble and know
That you yourself and no one else has made it
Sophocles, Ajax
Theseus is a project by Adobe research which lets you debug your Node.js code in their Open Source editor Brackets. It has some interesting features like real-time code coverage, retroactive inspection, asynchronous call tree.
Node.js Tools for Visual Studio 2012 or 2013 includes a debugger. The overview here states "Node.js Tools for Visual Studio includes complete support for debugging node apps.". Being new to Node.js, but having a background in .NET, I've found this add in to be a great way to debug Node.js applications.
Visual Studio Code has really nice Node.js debugging support. It is free, open source and cross-platform and runs on Linux, OS X and Windows.
You can even debug grunt and gulp tasks, should you need to...
I wrote a different approach to debug Node.js code which is stable and is extremely simple. It is available at https://github.com/s-a/iron-node.
An opensource cross-platform visual debugger.
Installation:
npm install iron-node -g;
Debug:
iron-node yourscript.js;
I created a neat little tool called pry.js that can help you out.
Put a simple statement somewhere in your code, run your script normally and node will halt the current thread giving you access to all your variables and functions. View/edit/delete them at will!
var pry = require('pryjs')
class FizzBuzz
run: ->
for i in [1..100]
output = ''
eval(pry.it) // magic
output += "Fizz" if i % 3 is 0
output += "Buzz" if i % 5 is 0
console.log output || i
bar: ->
10
fizz = new FizzBuzz()
fizz.run()
If you are using the Atom IDE, you can install the node-debugger package.
Using Chrome Version 67.0.3396.62(+)
Run node app
node --inspect-brk=0.0.0.0:9229 server.js(server js filename)
Browse your app in chrome e.g. "localhost:port"
Open DevTools.
Click the the node icon beside the responsive device icon.
There will be another DevTools window that will pop out specifically for debugging node app.
There is built-in command line debugger client within Node.js. Cloud 9 IDE have also pretty nice (visual) debugger.
I put together a short Node.js debugging primer on using the node-inspector for those who aren't sure where to get started.
Visual Studio Code will work for us in debugging.
Use Webstorm! It's perfect for debugging Node.js applications. It has a built-in debugger. Check out the docs here: https://www.jetbrains.com/help/webstorm/2016.1/running-and-debugging-node-js.html
If you need a powerful logging library for Node.js, Tracer https://github.com/baryon/tracer is a better choice.
It outputs log messages with a timestamp, file name, method name, line number, path or call stack, support color console, and support database, file, stream transport easily. I am the author.
Assuming you have node-inspector installed on your computer (if not, just type 'npm install -g node-inspector') you just have to run:
node-inspector & node --debug-brk scriptFileName.js
And paste the URI from the command line into a WebKit (Chrome / Safari) browser.
Just for completeness:
The PyCharm 3.0 + Node.js Plugin offers an awesome development + run + debug experience.
Start your node process with --inspect flag.
node --inspect index.js
and then Open chrome://inspect in chrome. Click the "Open dedicated DevTools for Node" link or install this chrome extension for easily opening chrome DevTools.
For more info refer to this link
There is the new open-source Nodeclipse project (as a Eclipse plugin or Enide Studio):
Nodeclipse became #1 in Eclipse Top 10 NEW Plugins for 2013. It uses a modified V8 debugger (from Google Chrome Developer Tools for Java).
Nodeclipse is free open-source software released at the start of every month.
There are many possibilities...
node includes a debugging utility
node-inspector
Code editors / IDEs (see debug instructions for one of the following)
Atom,
VSCode
Webstorm
and more
Debug support is often implemented using the v8 Debugging Protocol or the newer Chrome Debugging Protocol.
IntelliJ works wonderfully for Node.js.
In addition, IntelliJ supports 'Code Assistance' well.
The NetBeans IDE has had Node.js support since version 8.1:
<...>
New Feature Highlights
Node.js Application Development
New Node.js project wizard
New Node.js Express wizard
Enhanced JavaScript Editor
New support for running Node.js applications
New support for debugging Node.js applications.
<...>
Additional references:
NetBeans Wiki / NewAndNoteworthyNB81.
Node.js Express App in NetBeans IDE, Geertjan-Oracle.
Use this commands
DEBUG_LEVEL=all node file.js
DEBUG=* node file.js
node file.js --inspect
ndb is an improved debugging experience for Node.js, enabled by Chrome DevTools
https://github.com/GoogleChromeLabs/ndb
node-debug -p 8888 scriptFileName.js

Cannot debug Karma tests in Webstorm

I have been looking for a few days around the Internet in order to find an answer but, so far, haven't found anything.
So here's my problem: I cannot debug Karma tests or my app.
I am developing on a CentOS 6.7 a web app with WebStorm 10.0.4
I am using TypeScript and Angular, and use Karma for unit tests and Protractor for e2e tests. I managed to set the Protractor debuging, which means I can set some breakpoints over my tests code and it will pause on it.
I am using Firefox 38.0.0 (can't use an other version). Chrome is not installed.
I've set a Karma run configuration and a Remote Firefox configuration.
Karma problems
When I run my Karma tests, it's all good. But when I want to debug them, I've got the following message:
No supported browser found
JavaScript debugging is currently supported in Chrome or Firefox.
App debugging problems
It's even worse : when I launch the remote firefox debugging, everything is fine until I put a breakpoint in WebStorm: then the app just freeze and I can't do anything.
What am I missing ? Is there more configuration to do ?
Your help would be very appreciated.
If you are still looking for the solution here is my solution:
I think debugging in WebStorm is only possible with Chrome. At least I couldn't find any word about firefox anymore.
After installing Chrome and JetBrains extension open settings of the WebStorm. Select Tools => Web Browsers and enable Chrome.
Since I did step 2, debugging was possible.
Hope it helps you too.

Is there an "immediate window" in Visual Studio Code to run Javascript?

Yes, I use F12 in the browser all the time to test out Javascript snippets with the console. I'm tired of that (for the moment anyway).
I've read that in Visual Studio you can use the immediate window to run Javascript interactively.. I've haven't tried it that hard. I think when I did it told me it can't evaluate while in design mode... ugh, what a pain.
I do like to use Visual Studio Code (sublime text historically) sometimes to just mess around with syntax of snippets. Would also be nice if I could just run Javascript there too quickly. Is there a package I could download in VSCode to do so? Or something already built in?
As of (at least) my current version of VS Code (1.5.2), the "Debug Console", while debugging, lets you run arbitrary JavaScript code as you would in the VS Immediate Window. (Similar to as you would for the Chrome Dev Tools Console.)
There is no Immediate Window unlike Visual Studio in VSCode. But you can still execute Javascript in VSCode.
Install the Code Runner Extension - https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
Open the JavaScript file in VSCode, then use shortcut Ctrl+Alt+N, the code will run and the output will be shown in the Output Window.
I've found this extension that makes a scrathpad for JS, that runs at the same time as you are typing: https://quokkajs.com/
Works on VS Code, Jet Brains, and Atom.
If you don't want to start a debugging session or installing an extension, a simple way to have a JavaScript console is to start Node in a Terminal.
View -> Terminal
Start node (without any argument -you'll need node in your PATH)
Now you have a repl with auto-complete and value preview.
It doesn't have the features of the Chrome Console, but I find it good enough for evaluating JS code while I'm working.
Run the command node in the terminal below the editor, this will create a node environment where arbitrary JavaScript can be entered. You must first have node (and apparently npm) installed from nodejs.
This might do it: https://code.visualstudio.com/Docs/runtimes/nodejs
Node.js is a platform for building fast and scalable server applications using JavaScript. Node.js is the runtime and NPM is the Package Manager for Node.js modules.
To get started, install Node.js for your platform. The Node Package Manager is included in the Node distribution.

debug Grails app's JavaScript from IntelliJ

I use IntelliJ to develop Grails apps and when testing locally, I usually launch the app from IntelliJ which runs the app in an embedded Tomcat server. IntelliJ provides JavaScript debugging, but until now I've always used Firebug, but the idea of being able to use IntelliJ for all my debugging is pretty appealing.
I tried setting a breakpoint in IntelliJ and lauching the app in debug mode from inside IntelliJ, but the breakpoint was ignored. I also tried launching the app from outside IntelliJ via grails-debug run-app, then connecting to it with a remote JVM debugger, but the breakpoint was still ignored. Does someone know how I can debug JavaScript of a Grails app launched from IntelliJ?
I'm using IntelliJ Ultimate Edition version 13
Actually you need to do some extra work for debugging JavaScript with IntelliJ. Here are some useful articles about how you can configure your IDE and browser for JS debugging.
http://blog.jetbrains.com/idea/2011/03/intellij-idea-debugging-javascript-in-google-chrome/
http://wiki.jetbrains.net/intellij/Debugging_JavaScript_with_IntelliJ_IDEA
After configuration you need to just run your Grails application in debug mode.

Run JavaScript file in NetBeans/Eclipse?

Is there a way to run a JavaScript file directly in NetBeans or Eclipse?
I feel it's time consuming to fire up a terminal, browse to that file and run it with node all the time.
Another NetBeans Node.js plugin with a Node.js project type and npm integration (I am the author of it) is described in NetBeans Tools for Node.js
Yes, you can debug using Rhino in "Run As" without leaving Eclipse:
http://wiki.eclipse.org/JSDT/Debug
http://www.eclipse.org/webtools/jsdt/debug/
If you'd like to debug it remotely on a Node.js instance, you can use:
https://github.com/ry/node/wiki/Using-Eclipse-as-Node-Applications-Debugger
If you'd like to remote debug a Chrome/Chromium browser:
http://code.google.com/p/chromedevtools/wiki/EclipseDebugger
The latter two options will use V8, which is Google's JS engine behind Chrome, which has also been implemented in Node.js. The first option will use Rhino, which is Mozilla's JS engine.
Yes, you can run a JavaScript file directly from the NetBeans IDE with the Node.js plugin:
Download NodeJS plugin from netbeans.org

Categories