Bird
0
0

What should you do to catch the crash at the start?

hard📝 Application Q15 of 15
Node.js - Debugging and Profiling
You want to debug a Node.js app that crashes immediately on start. You run node --inspect app.js and connect Chrome DevTools but can't find where it crashes. What should you do to catch the crash at the start?
AAdd <code>debugger;</code> inside app.js after the crash line
BRun with <code>node --inspect-brk app.js</code> to pause before code runs
CRun <code>node --inspect app.js</code> with extra logging
DUse <code>node debug app.js</code> instead
Step-by-Step Solution
Solution:
  1. Step 1: Understand crash timing

    If the app crashes immediately, you need to pause before any code runs to inspect it.
  2. Step 2: Use correct flag to pause early

    The --inspect-brk flag pauses execution on the first line, letting you catch early crashes.
  3. Step 3: Evaluate other options

    Adding debugger; after crash won't help if crash happens before it; extra logging may miss early crash; node debug is outdated.
  4. Final Answer:

    Run with node --inspect-brk app.js to pause before code runs -> Option B
  5. Quick Check:

    --inspect-brk pauses early to catch crashes [OK]
Quick Trick: Use --inspect-brk to pause before app starts [OK]
Common Mistakes:
  • Placing debugger after crash point
  • Relying only on logs for early crashes
  • Using deprecated debug command

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes