NodeJS - a step-by-step debugger for NodeJS - debugging

I'm looking for effective way for step-by-step debugging NodeJS server code. At this moment I use dozens of console.log()'s and it's extremely hard. The perfect tool is one that would allow me to check the values of every variable in stack and trace my program line by line. Prefered OS = MacOS/Linux. Is it possible?

Basically, Node.js is built on top of V8, so its debugging capabilities are also built on top of V8's debugging capabilities.
V8 has an included debugger which can be accessed via TCP on port 5858.
So basically all you need is a frontend which is able to connect to port 5858 and talk V8's debugging protocol.
One option is to use node-inspector which basically provides a debugging UI in your browser. Unfortunately, it does only work with Google Chrome and Apple Safari (which for me is no problem, but there may be others ;-)).
Another option is to use a plugin for Eclipse.
And, last but not least, the built-in debugger of Node.js (which always reminds me of MS-DOS's edlin) is also just a front-end for this TCP debugger, just a built-in one.
And of course, there are much more options ... these three were just the first three ones that came to my mind ;-)

How about this?
You can try to test for Nodeclipse version 0.2.0 beta.
http://www.tomotaro1065.com/nodeclipse/
It will help you to debug node apps easily.
GENERATING OF EXPRESS PROJECT
Select the [File]-[New]-[Project] menu.
Select [Node]-[Express Project], and push [Next] button.
Enter [Project name], and push [Finish] button.
DEBUGGING
Open the JavaScript source files that you want to set breakpoints.
Double-click on the ruler at the left end of the line you want to set a breakpoint.
If you want to remove a breakpoint, double-click on the ruler again.
Select the main source file of Node Application on the Project Explorer,
open the context menu by right-clicking,
select the [Debug As]-[Node Application] menu.

Use node-inspector to provide the node debugging environment you're looking for. It's fantastic.

Check WebStorm. It is a great IDE, and also you can directly run your nodejs code, or connect to a debugging-enabled node process already running. In both cases, WebStorm provides what you are looking for: trace program execution line by line and on every line check the state of every variable.

Try nodeunit npm module for testing nodejs server side codes.

Even though question is very old, there is a awesome IDE from Microsoft "Visual Studio Code" which is developed in intention with Javascript (Typescript) which is capable of debugging Node JS projects
Checkout this link https://code.visualstudio.com/docs/nodejs/nodejs-debugging

node inspect built-in CLI step debugging
It took a while, but at some point Node finally added built-in debugging:
node inspect main.js
and this leaves you at the first line of the program.
Navigate with:
n step to next line
s step into function
c continue
o step out
h get help
In order to view variables or inject code, you need to first enter REPL mode with:
repl
and then you can run commands as in a node interactive session, e.g. to see the value of a variable just write the variable name:
myvar
It is awkward to have to type those four characters repl all the time, but I don't know any alternative.
You can also add a debugger statement to where you want to break in the program after a c:
const i = 1;
debugger;
i = 2;
Related question: How do I debug Node.js applications?
Tested in Node.js v10.15.1, Ubuntu 19.10.

Related

get shell version of run configuration in a JetBrains IDE

I'm using PyCharm, but I assume that this is similar for all the JetBrains products.
PyCharm has a very convenient UI for editing runtime configurations.
But currently I feel like there is too much UI between me and the actual code execution.
I'm using python + docker and I would like to know what exactly the IDE is doing.
Is it possible to export a runtime configuration to terminal commands?
If you start a run configuration, you get a 'run' tab at the bottom of your window which shows a shortened version of the command. Basically the interpreter and the script. But it definitely doesn't show everything that is going on (for example, in my python+docker setup the published ports are not shown).
Playing around with the UI, I couldn't find the shell version of my runtime config.
And in the docs, I didn't find anything either.

golang breakpoints not work in intellij idea 2016.1.1

I was debugging a GoLang program. I set break points and run the debugger. But the break points only works the first time I run the debugger and failed in the second, the third, and all following debugging whatever I do. I cancelled them and reset them, I close the debugging window and open a new one, I change the settings in the "Breakpoints" tool window. All these didn't work at all.
What's the problem?
Update, this has been fixed in the latest release of the plugin, please check it out
This is a well known problem and it lies in delve not the plugin itself. Please see this this issue for further reference.

Test Suite Execution Jubula

I've been looking at Jubulas automated functional testing tool and following along with the tutorials, but I've become stuck before I ever even got off the ground with it. The user manual provided with the installation hasn't given any answers and I can't find anything in blogs dedicated to Jubula.
My question: I have my test suite, complete with test cases & steps, all set up and ready to go. I've mapped my objects using the editor. I've started the AUT and connected to it. All I have to do is start the test execution.... I click start.... nothing happens.
The Java application is visible (it's a simple calculator) and I can interact with it. But I don't get any dialogue boxes when I press start, which is what is supposed to happen according to the tutorial.
Has anyone tried Jubula and had this problem?
Two things come to mind.
If the "Start Test Suite" button is disabled, then it means you still have some sort of a problem stopping the Test Suite being executed (e.g. missing data or object mapping).
If the "Start Test Suite" button is enabled, then it might just be that you need to select a Test Suite to execute from the drop-down menu (opened by clicking on the small arrow next to the green button).
I had the same problem but at least I got a report about the tests failing. After I specified the JRE for the AUT (this setting is only shown if you click on the advanced or expert button) my tests finally started to work.
I think it's none of the previous answers. If you get a Failed-test report or your Start Test Suite button is disabled then it's pretty obvious. You can find those mistakes mentioned in documentation/blogs.
BUT! There are two errors which leave no traits; no error messages, nothing in logs.
1.) If there's a version incompatibility If you installed Jubula from a standalone installer or from Eclipse marketplace then it will work. But if you put it together for yourself then you cold mix up the components. I have an answer on these issues:
Jubula doesn´t recognize running AUT after upgrade to 2.0
2.) If you mislead your AUT-agent by starting an other .exe It has exactly the symptoms mentioned in the question. It's happening because the application has the Remote-Control (rc) plugin started in it and the AUT-agent is notified about the start. It tries to identify the process within the AUT-configs listed in the client's (testexec's) database and it misidentifies it.
You can solve this by adding each run-situation as a different AUT-config in your database. It's mostly about location in the filesystem: about where the exec process is launched from. I.e: debug-local (from Eclipse launch-bar), exported-local (for Delta-pack exports), QA-local (if you have PDE in your build) etc.

Debug PostgreSQL function using pgAdmin

I refer this to enable the debugger in the PostgreSQL server in order to debugging the plpgsql function by stepping through the code using pgadmin.
I have already set shared_preload_libraries = '$libdir/plugins/plugin_debugger.dll' in the postgresql.conf, run pldbgapi.sql , and restarted the server.
These steps should have been run successfully and plugin_debugger.dll should be loaded successfully as can be verified by using the command show shared_preload_libraries, and I can see the debugging option in the context menu with a right click on a function in pgAdmin.
When choosing "Debugging" --> Debug, a window pops up to allow me to enter the values for the input parameters. But after that, when I press OK, it does not respond at all.
Any ideas or did I miss something in the setup of the debugger on the server?
I am using PostgreSQL 8.3 and pgAdmin 1.14
You have to enable debugging in two places. On PGAdmin and on the database itself. That article you referenced does a wonderful job explaining it but there were some nuances.
PGAdmin
When updating your postgresql.conf file to load the debugging library, I was running PGAdmin on Windows so the file was here:
C:\Program Files\PostgreSQL\9.4\data\postgresql.conf
And the path to the plugin_debugger.dll was actually
$libdir/plugin_debugger.dll
not
$libdir/plugins/plugin_debugger.dll
as specified in the article. So your postgresql.conf would need a line like this
shared_preload_libraries = '$libdir/plugin_debugger.dll'
Search for the actual .dll if you're in doubt. If you're on Linux the file you'll be looking for is plugin_debugger.so. Don't forget that changing the postgresql.conf file will require a restart for the change to take effect.
PostgreSQL Database
Assuming you're running your PostgreSQL database on a Linux server this gist does an excellent job at explaining how to download the dependencies for enabling debugging. Make sure you're running as root when you install.
The part that's easy to miss is issuing the command against the actual database you want to debug. For newer versions on PostgreSQL all you'll need to do is this:
CREATE EXTENSION IF NOT EXISTS pldbgapi;
If that doesn't return an error, you should be good to go.
Some additional things of note:
As mentioned above, you can only debug when running as a super user account
From their docs you can only debug pl/pgsql functions. So if your function says something like LANGUAGE c PGAdmin won't even show a right-click Debug menu option when you select the function. Look for something that has LANGUAGE plpgsql and the Debug menu should show.
Ken,
Have you tried pgAdmin 1.8 to rule out issue with PgAdmin 1.14/ PostgreSQL 8.3 interaction. It's been a while since I've used 8.3 and for the article I wrote -- which you are referring to, I was testing with 1.14/ PostgreSQL 9.1 so it could very well be an issue with the interaction with older version. Unfortunately I don't have a 8.3 anymore to test with.
I vaguely remember having the issue you had once, but it was when I had another shared library in my postgresql.conf in addition to the pldebugger. Can't remember which one that was, but removing the other shared library fixed my issue.
Hope some of these suggestions help,
Regina
I had the same problem.
Make sure the only shared lib you´re loading in the postgres.conf is the debugger.
Nothing else. Not even the profiler.
If you get a SSL error when trying to debug a function, reconnect to the server.

Selenium store result of web service/AJAX call

Is it possible to store the result of a web service/AJAX call into the store element, so that its value can be used in multiple locations.
The reason for this is we would like to have an automated test suite that uses data defined in a database. This would make it much easier to change bulk data in the tests (instead of searching through all of our test cases to change the data).
I understand that we can create a test case at the beginning of our test suite that defines all of this data however, we would like to easily switch between data sets without having to re-type each value.
I'm not sure how you can do what you're asking. It would be cool to learn. But let me give you a different approach which is very easy. I can answer any questions you may have. Create 3 different commands in your Selenium IDE to start things off, where your target for the open command is the path of the page you're automating.
Command: open
Target: --path--
Value:
Command: storeExpression
Target: 123
Value: var_number
Command: type
Target: TextBox1
Value: ${var_number}
Then use the export option in Selenium IDE as Java code (or another language). You won't have the Options > Format > options unless you turn on "Enable Experimental Features" in options. Choose "JUnit 4 (Remote Control or RC)"--Selenium 1. I'm not familiar with "JUnit 4 (WebDriver)"--Selenium 2 yet, but it's a bit newer, and not as much documentation. Then download Eclipse Classic, the Java JDK, the Selenium client driver for Java (on the Selenium site)--dll #1, and download JUnit 4--dll #2. Import both of those dll files into the Library tab (in Eclipse classic) after creating a new project in the project wizard, and open your export code that was exported using the Selenium IDE format export. Eclipse should be configured to automatically compile your code by default. Then just create an loop in the Java code and repeat the commands above. Then connect to your database from Java (with some simple SQL connection code), and read your data from the result set inside of your loop. Then right click in the Eclipse file explorer and choose JUnit on your unit test to launch a Mozilla Firefox instance to have it automate your loop. Or you can launch any other browser to run your JUnit test.. just change "*chrome" (aka Mozilla not Google Chrome) to "*iexplore" (Internet Explorer) or "*googlechrome" (Google Chrome), etc... for a browser of your choice in the Java code.
Pardon my jargon on "dll files". I meant to write assemblies or libraries. In Java, the correct term would be a *.jar. I'm use to writing in .NET code. If you choose to run your unit tests in .NET, then you will need to repeat most of what I have above, but instead download NUnit and use Visual Studio rather than Eclipse. The documentation is much better for JUnit, so that's why I went that route. That statement might not be correct. That's just what I found to be true from observation when I did a proof of concept for my company.
Oh, and because you're using client drivers, you need to have the Java (JUnit Test) program connect to your Selenium Remote Control Server. So you must download the Selenium server also. Then call the Jar from the command line in Windows. It must be running before running your JUnit test. This server won't run unless the JDK is installed on your machine!
java -jar selenium-server-standalone-2.0rc3.jar
The contributed user extension: http://wiki.openqa.org/display/SEL/global makes use of the global array globalStoredVars which you should be able to use.
I started recently to test a multilanguage website using Selenium with javascript, see Testing-a multilanguage website with selenium

Resources