0

I have started using Node Debugger but ran into an issue with placing the debugger; within a function code block.

For example:

let listAll = () => {
    debugger;
    console.log('getting all notes')
}

When inserting debugger; inside a function code block and running node inspect notes.js - every time I use cont,c command then it skips over this debugger statement.

However, if I take it out like so:

debugger;
let listAll = () => {
    console.log('getting all notes')
} 

When running node inspect notes.js and using the cont,c command - it will stop at the debugger;

Also when trying to use the next,n command within the debugger console, it just jumps from one expression block to another and skips over the code within the code block.

I just recently updated Node to 8.6.0 but this is my first time using node inspect.

EDIT:

I am exporting the test function at the bottom of my file, but not invoking it within the same file.

module.exports = {addnote, logNote, listAll, getNote, removeNote}
  • 1
    `listAll` is a function. Do you call it somewhere? – Gosha_Fighten Oct 02 '17 at 21:28
  • Do you know for sure this function is being called? To hit the debugger you must be executing the line it is on – Michael Hancock Oct 02 '17 at 21:29
  • I am exporting the function to use in my (app.js) I must call the function within the same file I'm debugging to use the debugger; statement within the code block? – brandenbuilds Oct 02 '17 at 21:31
  • Yes, otherwise, its code won't be executed. So, code execution won't be broken on debugger. – Gosha_Fighten Oct 02 '17 at 21:32
  • So it would it make more sense to add the debugger; on the main(app.js) file where I am actually invoking the function? – brandenbuilds Oct 02 '17 at 21:33
  • So you export it, do you still actual invoke it? AKA where is the `listAll()` call line? – epascarello Oct 02 '17 at 21:34
  • You import your function, but not execute it. To execute it, you need to use round brackets after the function name: `listAll()` – Gosha_Fighten Oct 02 '17 at 21:34
  • I do invoke it with my app.js. However, I see the problem after reading through the comments. The function is only invoked when a certain command is run for example `node app.js list` - which then invokes the listAll function. – brandenbuilds Oct 02 '17 at 21:38
  • What does `app.js` look like? – Gosha_Fighten Oct 02 '17 at 21:40
  • I figured out my issue which you @Gosha_Fighten helped figure it out. The debugger works when I invoke the function by passing the appropriate command into command line `node app.js list` Now the function runs and it stops on the debugger. Before I was trying to inspect my notes.js file which just had the function and not my app.js file when running `node app.js list` - which invokes the function. – brandenbuilds Oct 02 '17 at 21:43
  • great to hear that! – Gosha_Fighten Oct 02 '17 at 21:46

1 Answers1

0

As pointed out in the comments, I was running node inspector on the notes.js where the function is just being created and not invoked.

When I run node inspector list on my app.js - this invokes the function and the inspector stops at my debugger; statement!

Make sure to invoke the function you place debugger; in!