Issues with breakpoints in ts-node - node.js

I faced a very strange problem. I have two working PC and one of them stop breaking on the breakpoints in one day. Another PC works properly the same as before.
I tried to reinstall Node JS, ts-node and then even hard reset for windows (I use Windows) but without any success.
Then I thought that probably issue in my project and I tried to clone hello world project from google tutorial and I found that I still can't debug with it!
So I successfully run an app on my port but breakpoint won't hit. This stop working in VS Code, in WebStorm and even Chrome debugger.
This is how I run an app: "C:\Program Files\nodejs\node.exe" --inspect --require ts-node/register C:\Projects\node-typescript-starter-master\src\index.ts
Then I opened dev tools from chrome and I see this:
Then I pressed "inspect" and I see message in console:
Debugger attached. Debugger listening on ws://127.0.0.1:9229/8bae9408-867c-4278-9148-b6c90b35a8ae For help, see: https://nodejs.org/en/docs/inspector Debugger attached.
This is the next window. Seems like I missing any files overhere.
Does this mean that something is wrong with my file mapping ?
Please, let me any suggestion what can be a problem.

Well, one of workaround is to don't use ts-node and just use default node js debugger config from WebStorm with adding TypeScript prelaunch compilation script.
Here is a screenshot how to configure:

Related

How to use intellij idea debugger with webdriverIO?

I have an issue on wdio test runner. I have set it up in IntelliJ Idea as described here: How to get wdio running through IntelliJ run/debug configurations? But, when I try to debug, nothing happens. The test is not stopping on a breakpoint, it just continues on running. Please help me to set up the debugger.
This config works for me. Breakpoints work
I have debugging works (with Angular, I thought it would be the same with Node) in Intellij with the following steps:
Run npm run start to start your server with debug.
Run your test config with debug too.
Now you can set breakpoints
Sorry for inconvenient pictures, I'm not allowed to directly post picture yet.

Debug node.js backend application with an IDE, e.g. WebStorm

I added in package.json this into scripts:
"debug": "NODE_PATH=src nodemon --exec babel-node src/run.js --inspect",
It is pretending that it is debugging but jumping on selected lines how it pleases. I'm not that "expert" in JavaScript (I'm Java) but really this is pain in ass.
How can I debug backend without debug? Srry I'm angry because this is second time I'm giving change to JavaScript and this is second time I'm furious about this stupidity.
Thanks for any hints.
P.S.: if there is better software, tool to debug please just refer to it
In WebStorm, the easiest way to debug the application started via NPM stript is using the icon in the gutter: open your package.json in editor, right-click the icon to the left of your script and choose debug:
See also https://blog.jetbrains.com/webstorm/2017/09/debugging-node-js-apps-in-webstorm/
Note that:
babel-node is deprecated and not recommended for using in production. To get ES6 code compiled on-the-fly, try running node with -r #babel/register. see https://babeljs.io/docs/en/babel-register
by running nodemon --exec babel-node src/run.js --inspect, you pass --inspect to your application, not to node interpreter, so this command doesn't start the debugger. Node options have to be specified before the javascript file, otherwise the passed options will be treated as application arguments, not as node.js args
Right now, VSCode(Visual Studio Code) is considered as best tool for development, which is light weight and user friendly.
You can get different extensions based on your requirement.
To debug node js in vscode, go to debug window -> add configuration -> type attach process -> press ctrl + space -> press enter on attach suggestion.
After that, run command, node "your file name" --inspect
Press F5, your debugger will be attached
Node js debugging using VSCode

Protractor Debugging Issue - Waiting for the debugger to disconnect

I am trying to debug protractor scripts on VSCode.
I edited the launch.json file but the debug console throws the below error.
Here is the VSCode Debug Console Output:
C:\Program Files\nodejs\node.exe --inspect-brk=45448 conf.js C:\Users\abc\AppData\Roaming\npm\node_modules\protractor\example/conf.js
Debugger listening on ws://127.0.0.1:45448/ab61a2d7-4b40-456b-86cb-838e94dfe5b0
Debugger attached.
Waiting for the debugger to disconnect...
I am not able to find a solution anywhere online either.
When you set your breakpoint in VSCode, you'll need to run the following:
node --inspect-brk ./node_modules/.bin/protractor conf.js
The path above assumes Protractor is installed in your node_modules/.bin/ directory locally in your project.
Next navigate to chrome://inspect. You will have to skip the entry point of Protractor and then you should hit your breakpoint. Make sure you are using node 8 to avoid getting polyfill-ed promises.
We go over this in detail in the ng-conf video. We kick off the test with a script that uses this e2e-debug command which is the equivalent to the above.

Debugging node app in WebStorm when run from gulp

I am using webstorm 10.0.2 and have used the bangular yeoman template to generate a project. I can run the gulp commands via the gulp window, and I can set a breakpoint in the gulpfile.js and it will hit it, but I can't seem to get it to hit a breakpoint in my server.js
It looks to me like the gulp file is launching another instance of node and thus when you do "debug" from webstorm you are just debugging the gulp.
I also tried with another project using yo hottowel but get the same thing - I am unable to debug the actual application through webstorm.
Can anybody tell me how to configure webstorm so that I can debug the actual server side node code but still use the gulp build tool?
I contacted JetBrains support back in May 2015 and their response was:
It seems this cannot be done quickly. In short, the problem is that serve-dev task starts new process (nodemon) that takes app.js
There is no workaround how to debug such spawned processes right now. We would really appreciate if you'll submit a feature request about it in our YouTrack: https://youtrack.jetbrains.com/issues/WEB
The only way you can try to avoid it - try to create a separate task that will run app.js directly without nodemon process and debug this task instead.
It seems the best option is to use https://www.npmjs.com/package/gulp-node-inspector

How to debug a basic node.js application (not http) on windows

I know how to debug http applications using node-inspector and iisnode. But can I use node-inspector to debug a non http node application, on windows?
I tried:
node debug test.js
It says:
debugger listening on port 5858
But opening http://localhost:5858/ in Chrome does not do anything.
BTW: running node debug test.js does start the command-line debugger which works. But it's nothing like node-inspector.
To use node-inspector, the right switch is node --debug not node debug
Here are the detailed steps:
install node-inspector globally (npm install -g node-inspector)
from a command-line window, run: node-inspector
open Chrome and go to http://localhost:8080/debug?port=5858. You'll get the node-inspector UI but without any running app.
from another command-line window, run your app with the --debug switch like this: node --debug test.js
refresh the Chrome tab and voila!
A few interesting points:
If you kill your app and start it again, just refresh the node-inspector tab. It will keep all your breakpoints.
To break automatically on the first line start your app with node --debug-brk test.js
Some links which might help you:
http://vimeo.com/19465332 (screencast from Ryan himself).
https://github.com/joyent/node/wiki/using-eclipse-as-node-applications-debugger
It says: debugger listening on port 5858
I wondered myself about this but since the Node.js documentation indicates that the debugger is accessible via a simple TCP protocol and says nothing about HTTP my guess is that no, it won't be available at _http://localhost:5858.
"V8 comes with an extensive debugger which is accessible out-of-process via a simple TCP protocol" - http://nodejs.org/api/debugger.html
Very recently Microsoft released the node.js tools for Visual Studio. It has the very comfortable Visual Studio debugging for node.js.
node-inspector could be very helpful.
Use it from any browser supporting websockets.
Breakpoints, profiler, livecoding, etc..
http://erickrdch.com/2012/09/debug-a-nodejs-app-with-chrome-dev-tools.html
FYI, in OSX 10.8, Chrome v26 doesn't seem to work, but Safari 6 does using the same instructions as above and using 0.0.0.0:8080 to conect.
There is another post by Danny Coates somewhere that says to do it in the following order:
Your node process: node --debug (or --debug-brk) my_program.js
Node-inspector: node-inspector
The browser pointed to 0.0.0.0:8080
If you are a noob like me on Windows, and you get 'node-inspector not recognized' or something about windows JScript error... despite global install, adding to PATH, etc. then this may help.
Navigate to C:\Users\urusername\AppData\Roaming\npm
Then run node-debug.cmd or node-inspector.cmd
You should get magical words like
Node Inspector v0.12.7
Visit http://127.0.0.1:8080/?port=5858 to start debugging.
Debugger listening on port 5858
Awesome. If you know of a better solution, please let me know

Resources