I read about node-inspector as a suggestion for debugging node code.
However I have found no clear instructions on how to use it, and the documentation is awful.
I installed node-inspector and then did
node-inspector --web-port=5858 &
I get a message saying
Visit http://127.0.0.1:5858/?ws=127.0.0.1:5858&port=5858 to start debugging.
which I do.
Now I get a blank console page.
But the docs stop here. What do I do next to actually debug my app?
Click the 'source' tab to see all the files used by your nodejs project. When the debugger starts it stops code execution at the first line automatically without setting any breakpoint, this lets you set more breakpoints if necessary. After setting breakpoints, click on 'Run' or 'Resume execution' button to proceed.
For the first usage you can follow next instruction:
Create new project with only index.js
var a = 0;
setTimeout(function() {
debugger;
console.log(a++);
}, 1000);
Open your preferred shell in project dir and execute node-debug index
Related
I'm tasked with creating a simple calculator application for entry to a programming course. I'm having issues with Terminal :(
I'm not looking for an answer to my overall task, I just want to know why Terminal wont RUN!! What am I doing wrong?
Steps as follows:
Create a directory that you will keep your Calculator application in. Call it
something sensible, like "Calculator".
Open up a command prompt and navigate to your calculator directory
Run npm init to create a new Node.js project. Use the default answer to every
question it asks you (just press "Enter") - don't worry if you don't understand
what all the questions mean!
If it doesn't do anything after the final question "Is this ok?", double-check
there's a file in the folder called package.json . If it's there, everything went
smoothly and you can exit the npm init process by typing in the console
Ctrl + C .
So my problem is... when I run npm, all that happens is my Mac asks if Terminal can access or change files in my system, I click yes, then Terminal doesn't do anything from there, no questions etc I just get:
I can't see package.json, so I take it it hasn't worked properly? How can I fix this to move on?
I'm using zsh on terminal.
Well, first off. What ide do you use? (Personally I like Visual Studio Code).
I'm not sure what the short command is for you to open up the terminal but just google it. Otherwise, you can click "Terminal" on the very top and open a new terminal.
When you do this, you will get a new window at the bottom of your screen. This window has some tabs, make sure you are in the terminal tab.
While there, type "npm init".
This will give you your package.json-file.
If you want to use your terminal for outputs I recommend you get nodejs too.
I thought the reason the new VS Code debugger stopped on the 'use strict'; in my file was because of some weird deprecatory behaviour in new versions of Node, or else because my code had some weird error in it.
Then I realised that "break on first line" is a thing, and one that people want. Why on earth is this a thing? I know that my script has a first line, thank you very much. I'd have bigger problems if it didn't. So why does the debugger need to do this?
In launch.json there is a property stopOnEntry which is set to true by default. If you don't want to Node Debugger to "break on first line" set this property to false.
Now a toggle for this exists:
--inspect vs --inspect-brk
The reason "break on first line" is a feature, is so that you can run your application, and have it stop on the first line before continuing.
This allows you to attach a debugger before Node has executed some of the code. This enables you to debug the very first lines of code, set more breakpoints, or step over the lines of code whenever you are ready.
This is actually a pretty common feature in a debugger, especially if you don't necessarily have a way to set breakpoints before you run the code.
I'm using node-debug and know which file and line for which I want to set a breakpoint.
Here's what happens:
debug> setBreakpoint('./services/search.js', 359)
Warning: script './services/search.js' was not loaded yet.
You can't list source code right now
Why can't I "list source code"? How can I add a breakpoint dynamically (without editing the source code to add debugger)?
I tried other tools for debugging, and would love to use Chrome Dev Tools, but don't think it's possible since our project is stuck on v0.12.3.
Also, some options are limited/tricky because I'm using Vagrant with a headless VM.
This is still a problem in node 6.
There is precious little information about it on the net, which is a shame.
However, node --inspect and then using Chrome does work.
I try to debug a Project in node JS with Visual Studio Code but i don't achieve.
I have built a simple project with the next commands:
express myExpressApp cd myExpressApp npm install npm
start
My file launch.json:
I select the Option “Launch app.js” in Window “Debug”. The application run without problems. I put a breakpoint:
I give in Chrome the address: http://localhost:3000/
Visual Studio Code says: “Pause on breakpoint”, but I don't see anything, I can press Continue and the application continues...
Edited: I use OS X 10.10 (I tested it and it works perfectly in Ubuntu.)
VSCode 0.8.0 has problems with node versions older than 0.12.0. Upgrade to at least 0.12.0 or wait for the upcoming VSCode 0.9.0.
When debugging with Visual Studio Code, there are many things you can do when you hit a breakpoint.
In order to go to the "debugging" view, you can either click the "bug" icon on the left or hit Ctrl + Shift + D.
You see Paused on breakpoint. in the Call Stack window. That window includes the callstack and you can double-click the different frames to navigate through the corresponding source.
You can also see the Variables window here to see the values of the variables (local/global/closure/etc.).
One of the more used functionality parts of debugging in VS Code is the debug console. In the debugging view, there's a little icon right next to the configuration that you're using that looks like the CLI character. You can either click that or just do a command palette search (Ctrl + Shift + P) for Debug: open Console. This will bring up the debugging console for your ad hoc debugging commands.
The documentation on VS Code debugging is quite robust, too, so I recommend you take a look at this.
I start the debugger with "slc debug" and Chrome starts up. I want to set a breakpoint on line 100 of report.js
I can't do it. Won't let me.
Any ideas why?
In other file such as events.js I can click on the linenumber and the blue breakpoint shows up.
Is the Strongloop node inspector any different from the standard one?
I got this problem too. Try this (sound weird), but its work for me :
type "slc debug"
the chrome will open up, with one new tab
explore to your "report.js" file, set break point at your line (Note : the break point will not show)
open up new tab at same chrome
type in the debug path (same like the one at step 2, or you can see it at your debugger). ex : http://localhost:8080/debug?port=5858
At the new debug tab, the break point will show up.
Hope it help, just sharing what i been through.
thanks.