Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 1.52 KB

Debugging.md

File metadata and controls

26 lines (18 loc) · 1.52 KB

Debugging

ℹ️ If you need to use your debugger extensively, you are probably not programming defensively enough. Use lots of small functions instead of a few big functions and don't assume your code will always follow "the happy path" of error-free code. Coding is not always 🌞 and 🌈. Please try to catch your Errors. ⚾

  1. The Absolute Easiest Way to Debug Node.js — with VS Code

    • Let's try setting that up together
  2. Use your Chrome Browser as your debugger

    • node --inspect-brk filename.js
    • Open in Chrome: chrome://inspect
  3. You can even debug Unit Tests such as Jest

    node --inspect-brk node_modules/.bin/jest --runInBand # $ARGS
    # or on Windows
    node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand %ARGS%
    
  4. ⚠️ Do not try these on insecure/open Wifi networks. More details in the Official NodeJS Docs

Final NodeJS debug logging tip: Try DEBUG='*' node filename.js because many packages will log additional info if you set set DEBUG='*' if they use the debug npm package. No breakpoints, but a great way to check which database or websites you are visiting in your app, for example.