Node.js provides built-in non-graphic debugging tool that can be used on all platforms. It provides different commands for debugging Node.js application.
🏝️ Now, considering an example where we add two numbers
const add= (a, b) => {
return a+b;
}
const result = add(3,4)
console.log(result)
🎻 store this file as add.js , Now in command promt type
node debug add.js
🎻 This command start debugging and stops at the first line as shown below:
💡 Command used in core debugger:
- cont, c - Continue execution
- next, n - Step next
- step, s - Step in
- out, o - Step out
- watchers - See the value of all expressions and variables added into watch.
- Pause - Pause running code.
- watch().
watch('result')
💊 In this output it shows undefined as it is executed before the result is defined.