Node inspector debugging - node.js

I am currently having trouble getting node inspector to work with Google Chrome. I am on Windows 7 64 bit.
here is info about node-inspector:
https://github.com/node-inspector/node-inspector
when I run the following
node-debug app.js
on a simple JavaScript file called app.js:
a = 5;
b = 6;
c = a + b;
console.log(c);
and I open up Chrome with the following URL:
http://localhost:8080/debug?port=5858
all I get is this empty page with nothing loaded except one little part of the Chrome debugging toolbar, no matter what I do, I even reinstalled Chrome ( and the Canary developer version too):
Anyone have any idea what could be going wrong? This is the simplest JavaScript application ever, and there node-inspector directions does not specify any other steps to take. Like I said, I resinstalled Chrome. I have node version v0.10.30, npm version v1.4.21 version and node-inspector version: v0.7.4.
Does anyone have a good idea how I can test Chrome debugging tools without involving node? I am new to all this.
When I installed node-inspector, I did get what looks like a warning:

Try starting it without node-debug wrapper.
So, install node inspector:
npm install -g node-inspector
In one terminal:
node --debug-brk app.js
In a different terminal:
node-inspector
Browse to http://localhost:8080/debug?port=5858

i had the same issue. i then uninstalled node-inspector, installed it again. closed the cmd prompt which installed node-inspector (maybe this step made the difference). opened another cmd prompt to node-debug my.js. i can see the source file now.

I had a similar issue where going to http://localhost:8080/debug?port=5858 would result in an empty page. However going to http://127.0.0.1:8080/debug?port=5858 seems to do the trick.

Related

Has Browser-Sync been deprecated to use globally?

Hello All and I was wondering if anyone uses Browser-sync with NotePad++. I use both VS Code and still fall back to Notepad++ when learning or experimenting. As of February 5th I could still use it globally as the simple web server and for hot reload.
I have it installed -g with npm and use a simple script loaded into the directory from cmd.
browser-sync start --server --no-notify --files "html/*.html", "js/*.js", "css/*.css"
That was all I had to do to localhost:3000 to load the HTML with all CSS styles and JavaScript.
But now it opens to the port 3000 but with a "Cant/Get" message and a console error message.
It always listed a warning message in the console. That you are not to use document.write(), but I guess it was part of how Browser-sync was set up. Now this is the error that it throws.
But in the terminal it shows Browser-sync watching ....
I was wondering if they thought it a vulnerability and now require a config file and it listed as a saved dev dependencies??
It was nice to use Notepad++ with the hot reload and using the cmd is good practice. You get spoiled with VS Code and the other IDEs.
Just wondering if anyone can make sense of the error message in the console. Or still can get it to work on a global level.

Issues with breakpoints in ts-node

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:

Cannot debug Nodejs with node-inspector: websocket_closed and Assertion failed: Unknown experiment canvasInspection

I try to debug my server.js app with node-inspector (v0.12.8), nodejs (v5.9.1) and chrome (v49.0.2623.112 m) under windows environment.
In a shell i do
node-inspector
Node Inspector v0.12.8 Visit http://127.0.0.1:8080/?port=5858 to start debugging.
In a second shell i do
node --debug server.js
When i go to chrome tab i obtain a message:
Detached from target
remote debug has been terminated with reason: websocket_closed
please reattach to the new target
In the console dev tool of chrome i can see either a message that inspector can't find experimental function canvasInspection (removed in the latest chrome version).
I'm doing something wrong?
Not the answer specifically, but as of Node v6, you can actually just use the --inspect flag when you start a process, and it will let you use the Chrome debugging tools instead of relying on node-inspector. Check it out:
https://nodejs.org/docs/latest/api/debugger.html#debugger_v8_inspector_integration_for_node_js
Hope this helps!
I had the same problem, I fixed it the way below:
1- Go and edit the following file in your currently in use nodejs path:
...\node_modules\node-inspector\lib\InjectorClient.js
2- Go to line 111. if you're using vim as text editor you can do it by command :111
3- Add the following if statement at line 111 and indent the next line.
if(NM.length > 0)
cb(error, NM[0].ref);
4- Save and re-run node-inspector.
Cheers!
I'm using MacOS Sierra, Node v6.3.1. But the solution is general.
I had also faced this issue , but after lots of googling and finding about this issue. The only thing work for me is listed below :
Open your Command Promp(cmd) & type node -v, it will show you the version of node installed on your machine.
If the installed version is something 5.x.x or 6.x.x , then proceed further.
just uninstall this node version from control panel.
Install the node release with version 4 . I've tested with Node version v4.5.0 & I hope it will work fine for all Node with version v4.x.x.
Uninstall the previous node-inspector with command npm uninstall node-inspector -g.
Then Install again with command npm install node-inspector -g.
Then start debugging .. :)

node inspector -brk not working

I am trying to use node-inspector with a simple script. I have some console logs in place so I can tell if it's running or not. I have tried 2 ways:
node-debug test.js
With this approach, the debugger opens in chrome, but does not break and runs without giving me a chance to enter break points.
In terminal window #1:
~ $ node-inspector
Node Inspector v0.9.2
Visit http://127.0.0.1:8080/debug?port=5858 to start debugging.
Open debugger in chrome. In terminal window #2:
node --debug-brk test.js
The script seems to be waiting, but the debugger window I opened has nothing going on, So I refresh the page. As soon as I do, I see my console logs (not breaking).
I'm running OSX Yosemite (10.10.1), Node.js v0.12.0, NPM 2.5.1, and Node-inspector v0.9.2.
Any ideas why this is happening?
This is a known bug when running on Node v0.12 and io.js, see https://github.com/node-inspector/node-inspector/issues/534

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