Debugging a node.js project in Visual Studio 2022 - node.js

I'm trying to expand a sudoku web application that I've checked out locally with visual studio 2022, namely this one: https://github.com/michel-kraemer/sudocle
My goal is to implement additional functionality and I'm using this as a learning experience in frontend development since I'm currently only doing backend. I can get the application to run in my localhost using node.js as detailed in the readme and I can modify some very basic things (e.g. changing texts) but to really get started, I would like to debug the application as it's running on my local server. The expectation is that I could set breakpoints in function that I want to modify to see the state of variables at runtime.
This is where I'm stuck. I've tried attaching the debugger to various processes and I can get it started from the next.config.js file, however I think it's not connected to my localhost then and I'm not sure how to trigger any functions from that point. Maybe I'm also misunderstanding the functions of a debugger in a web application.
For what it's worth, those are the sites I've been reading trying to solve my issue, so far with no luck:
https://github.com/Microsoft/nodejstools/wiki/Debugging
https://learn.microsoft.com/en-us/visualstudio/debugger/troubleshooting-breakpoints?view=vs-2022
https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_auto-attach
F5 or Start Debugging Button is Greyed Out for Winform application?
https://learn.microsoft.com/en-us/visualstudio/debugger/debugger-feature-tour?view=vs-2022
I hope a more experienced dev can help me out here.

Related

How to debug a serverless framework plugin?

I've searched throughout google about this question and I had no success...
I want to work on a serverless plugin fix, but I don't know how to attach the process to debug the code.
Currently, I'm using vscode and the plugin was developed using nodejs + typescript.
Does anyone have any tip or article explaining how to do that?
As every other process, that you want to debug, you need to run it and somehow connect the debugger to it.
You need to remember, that Serverless Framework is written in JS/TS, so it runs in Node.js. So you can debug it quite easily, if you are developing your Lambdas in Node.js, as it's quite common environment.
How to do it using Jetbrains/Webstorm/IntelliJ
Go to your node_modules directory and find the source code of the plugin, that you want to debug.
In the source code place the breakpoint.
Now Create a new "Run configuration" in IDE for NPM, that should be similar to mine:
4. Make sure you've chosen the correct package.json!
5. Now simply start debugging, like you normally do, but choose the run configuration, that you've just created.
In my example I'm using package script from package.json, but it could be also any other script, that triggers serverless deploy or serverless print in the end.
And that's it! Breakpoints should be triggered normally, like when you debug your own JS code.

Cannot GET / error

looked for couple of hours, on how to solve that, but no luck.
I am using VS 2017 preview edition, and trying to open ASP.NET core 2.0 web application, that uses Angular template
when i open the site (f5 or ctrl-f5), the web-browser getting opened with the message
Cannot GET /
I don't know what causing that and how to fix that, tried to clean/rebuild/restart VS/change project port number/restart the computer, what else can I do to solve that?
Depending on what error you have in the client application, the server might not start at all. Local errors like undeclared locals are seldom a problem.
Usually, the web server does not start when a dependency of the module marked as bootstrap is missing, like, for example `entryComponents'.
Another thing that can cause the boostrap to fail, is a missing file: in this case you should have a look at templateUrl and styleUrls.
Manually compiling via ng build (or better ng build --prod) will point you to the offending code.

Debug node.js web application that has been launched via a Gulp task

I have a web application that is written in node.js and gets started using a gulp command. When the application first starts, before the server is running, debug points may be hit in WebStorm (or in any IDE or command line tool). However, after the server is running and I go to the interface in my localhost I can no longer hit debug points inside the application. This is not being caused by client side code as the debug points are in server code.
I have read the answers that involve using the node-inspector and that has not solved my problem because of configuration files that are not getting read when starting the debugger in node inspector.
I'm a bit surprised that there is so little on here about this issue. Is it not a normal problem that other developers face? Thanks in advance for the help.
My workaround for this may not be sufficient for every case. I was modifying JavaScript files and didn't actually need the configuration files, after loading, to be able to test my changes. I did the following:
Wrote a line in my app.js file that set the variables I needed. (these would have been tasks ran in Gulp)
I then started the app as a Node.js app and was able to debug it as normal.
If any of my views had been updated, or anything else that was being managed by Gulp, then I could have simply stopped the server, started it again via the Gulp command, and then stopped again and restarted as a Node.js app.
This did not solve the issue in my OP but it was a good enough workaround to get debug points in the JavaScript.

Selenium webdriver UI tests over-riden by LocalHost

i have created unit tests for my web project but i have come across an error whereby the tests are being ignored and Visual Studio 2012 is running my localhost instead. i cannot use localhost to run my tests as there are a lot of java resources and overlays which aren't displayed. Essentially that is the point to UI testing that you test the correct interface.
The code i used in a blank project - runs perfectly and completes the test with no issues but since i need to include this into my web project, i need a way to stop Visual Studio running the localhost and get it to execute the console application test so that my selenium webdriver can run the test properly.
using: Visual Studio 2012
Selenium (webdriver)
chrome driver (latest version)
c#.Net
example code:
IWebDriver _driver;
ChromeOptions options = new ChromeOptions();
options.AddArgument("--start-maximized");
_driver = new ChromeDriver(options);
_driver.Url = "http://theURLimTesting.com/";
var verificationErrors = new StringBuilder();
_driver.Navigate().GoToUrl("http://theURLimTesting.com/");
_driver.FindElement(By.Id("Username")).Clear();
if anyone could help me and provide a solution as to how to run these tests without excluding them from the project and without having to create a proxy - i would be very grateful, as i am very much a novice.
UPDATE: as #mutt 's answer helped steer me towards the right direction with being able to resolve my question i marked the answer as right - i have managed to configure the error and create a work around and tweaking some settings to get this to work and now i can run all tests inside of the web application properly and they all function properly with executing and closing themselves in the background when done.
Separate your unit tests from the web project and it should work. Since you have them together your webapp probably has a default start page so when you "play" it will load that and VS is scoped to that browser running on IIS Express instead of the regular browser.
Personally I would have thought it would still work since Selenium is hitting the driver package that is referencing the browser, but I'm not sure what all VS is doing when it runs the webapp. If you want it with the console then move all your unit tests to the console project and they should still work on the WebApp because they will be hitting the server version and not the locally run project.
Update:
It looks like it is process bound. So Selenium and visual studio are sharing the same process. VS2008 debugging with firefox as default browser - how to make the debugger stop/close on exit?
Update2:
It looks like you should be able to determine if the process is being utilized. Then the question would be can you just kill it in your unit test script so that it will be forced to create a new one... Programmatically determine if code is running under IIS Express

Debugging a deployed cloud service app

How can a deployed cloud service application be debugged?
I am trying to render a RDLC report in my application using Topics & Subscriptions.
Whenever I run the cloud app locally, I don't receive any errors. But as soon as I deploy it over the cloud, I get an error which aren't described up to an extent so that it can be rectified.
I found that the error comes when the report is ready to be rendered and not anywhere else.
I am looking for a possible mechanisms (inserting breakpoints like we do locally, etc.) using which it is possible to debug a deployed cloud app.
Since I am using VS2012 Express & professional, intellitrace does not work here.
You need to enable Remote Debugging for your Role, and you will be able to debug your code in the cloud with any type of Visual Studio.
I don't think you can, however Intellitrace was build for that purpose. You enable Intellitrace in your cloud instances, and then you can "playback" that instance locally, thus debugging and spotting the exceptions thrown.
Here's MSDN's article on that
http://msdn.microsoft.com/en-us/library/vstudio/dd264915.aspx
Having Intellitrace only in the most expensive version of Visual Studio makes developing for Azure far more expensive than it is advertised at. There are some situations, such as when a role is starting up, that you pretty much can't do anything without Intellitrace. If you find that you are in one of those edge cases 'evaluate' VS ultimate in a local virtual machine. You may need to re-evaluate at some point in the future, in which case you will need another VM.

Resources