I've installed node-inspector, and have started it with node.
When I try to start debugging mode with --debug-brk, it still errors out (it's this error I'm trying to debug)
It does not break on the first line...
$ node --debug-brk app.js
debugger listening on port 5858
/base_controller.js:59
files.forEach(function(file) {
^
TypeError: Cannot call method 'forEach' of undefined
at Object.oncomplete (/base_controller.js:59:9)
installed node-inspector : https://github.com/node-inspector/node-inspector
try below steps:
first: node --debug-brk app.js
second:node-inspector
then:
open a new winow in chrome,open url:
http://localhost:8080/debug?port=5858
you can debug your code now !
Maybe you are not running the latest version (it happened to me). Please do
$ node
> process.version
That should give you the last version. You can update here: http://nodejs.org/
Related
When I try to use debugger in node to open debugger, I get an error 'Timeout (2000) waiting for 127.0.0.1:9229 to be free'. How can I resolve this and run the debugger correctly ?
function foo() {
var a = 5;
debugger
console.log(a)
}
foo()
I have already tried changing the port using node inspect --port=9230 app.js and it doesn't work.
Try this:
node --inspect-brk app.js
replace app.js with your file name that you want to run, and you can insert your additional command alongside with this line.
I had the same problem, it took me hours to figure it out...
Run the following command:
node inspect --port=9228 file.js
I had the same issue by using VS Code. VS code document helps. Replace program.js with your js file name.
https://code.visualstudio.com/docs/nodejs/nodejs-debugging
if the program should not start running but must wait for the debugger to attach:
node --inspect-brk program.js
Use node --inspect-brk {js file name} instead. It will work.
--inspect-brk=[host:port]
Enable inspector agent
2.Bind to address or hostname host (default:127.0.0.1)
3.Listen on port port (default: 9229)
4.Break before user code starts
I think the issue here is the command you give to node, it should be node --inspect..
You are missing the -- in front of inspect :)
Install
npm install --global node-inspect
Then
node-inspect script.js
Ref: https://www.npmjs.com/package/node-inspect
I'm facing an error:
Starting inspector on 127.0.0.1:9229 failed: address already in use
How can I resolve this error?
You can do it this way:
node --debug=5412 app.js
You can also use --inspect option for node version >= v8
node --inspect=5622 app.js
See for More Help.
use param "--inspect"
node --inspect=0.0.0.0:[your port] app.js
How can I just use the simple node cli/repl debugger with Jest?
The Jest documentation uses node-inspector, but it is outdated/deprecated as of Node 6.3. I tried the recommended command anyway on Node 7.7.4:
node --debug-brk ./node_modules/.bin/jest --runInBand --no-cache [your_test_file]
But this simply hangs on the following (assumedly waiting on node-inspector):
(node:13452) DeprecationWarning: node --debug is deprecated. Please use node --inspect instead. Debugger listening on 127.0.0.1:5858
I added --inspect as specified by the warning, but even then execution doesn't stop on my debugger statement in Chrome DevTools.
This seems overly complicated for a very simple use case.
I found the following command works:
node debug ./node_modules/.bin/jest --runInBand --no-cache [your_test_file]
...but with some quirky behavior. When the debugger first stops you will see:
break in node_modules/jest/bin/jest.js:10
8 */
9
>10 'use strict';
11
12 require('jest-cli/bin/jest');
debug>
Apparently Jest always injects this breakpoint so that you have time to open Chrome DevTools (irrelevant in our case since we're only going to use cli/repl).
Continue past this breakpoint with c, and after a short time (without any indication of course that things are progressing along) you should see your breakpoint:
break in webpack/assets/react/components/presentation/Feed/Comments/Comment/commentSpec.jsx:12
10 var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(_comment2.default, { loading: true }));
11
>12 debugger;
13 expect(wrapper.find(_button2.default)).to.have.length(1);
14 });
debug>
The last weird thing is you need to type repl to inspect objects as described in Node Debugger and Inspecting variables using node's built-in debugger?
The combination of all these steps was not immediately obvious to me while reading the documentation, so I hope this answer helps someone get over the hurdle faster.
From node v8.4 the debugger keyword within the code is fixed for VM context. Refer this git comment.
1.Type debugger keyword in your Jest code:
describe('Testcase definition', () => {
it('should be defined with subobjects', () => {
debugger; // <-- This keyword breaks on Chrome inspect
expect(true).toBe(true);
});
});
Command to Run:
node --inspect-brk --inspect ./node_modules/.bin/jest -i tests/mytest.test.js
Now open chrome://inspect/#devices on Chrome. Voila!
I wrote the following code using 'readline-sync' dependency.
var readlineSync = require('readline-sync');
function main() {
printMenu();
var userName = readlineSync.question('Please enter your choice:');
console.log(userName);
}
main();
I ran this code from WebStorm trying to use the WebStorm console window.
I got the error:
Error: The current environment doesn't support interactive reading
from TTY. stty: when specifying an output style, modes may not be set
When I run it from linux terminal the code works with no error. I understand from the error message that 'readline-sync' cannot work from WebStorm console. Do you have any idea how to solve it?
I found out the answer.
type in WebStorm terminal:
$ node --debug-brk
Web storm will give you the port number the debugger is listening to. On my machine it was 5858. Then press 'Ctrl+C'.
Create a new debugging configuration as the following one:
In WebStorm terminal type again: "$ node --debug-brk main.js "
put a breakpoint somewhere.
Click the debugging icon
Happy Debugging!
I can do:
I can test node.js modules using nodeunit.
I can debug my node.js express site using node inspector.
But how to debug nodeunit test using node inspector?
I tried, but not working:
nodeunit --debug myNodeUnitModule_test.js It's not working.
I tried to install nodebug.
And used it like this: nodebug /usr/local/bin/nodeunit myNodeunit_test.js But it's not working neither on ubuntu (No such file or directory) nor on mac (env: node\r: No such file or directory)
Almost works
node --debug /usr/local/bin/nodeunit ./routes/edit/bodyTelInfoArraysToObject_test.js
where /usr/local/bin/nodeunit is path taken by command which nodeunit
got output:
debugger listening on port 5858
and test executed there.
But I can't jump in debuggin: when I open url localhost:8080 in chrome to watch debugging:
first load I see empty file list
second load: page not found.
On my nodeunit test I wrote debugger to stop on debug there.
But nothing.
In your tests insert debugger; command
exports['Main test'] = function(test){
debugger;
test.expect(1);
test.ok(true, 'Must be ok');
test.done();
};
And start all this
$ node --debug-brk `which nodeunit` test.js
Now in browser press F8, then F10, and you are right on the next line after first debugger; command in your test.
But I prefer to start everything with node-supervisor, that restart test automatically when test finished or files in project directory changed:
$ npm -g install supervisor node-inspector
$ # console 1
$ # supervisor restarts node-inspector when it quits
$ # ignores file changes
$ supervisor -i . -x node-inspector .
$ # console 2
$ supervisor --debug-brk -- `which nodeunit` test/index.js
Solution found:
in console:
node --debug-brk `which nodeunit` ./path/To/My/NodeUnitTests/nodeunit_test.coffee (Attention: `which nodeunit` is in back quotes)
in another console:
node-inspector &
And in google chrome open: http://0.0.0.0:8080/debug?port=5858
Here I see nodeunit debuging from the start. Click continue execution several times in browser until jump to nodeunit test, where I have debugger; string. So I debugging my nodeunit test with nodeinspector