ℹ️ 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. ⚾
-
The Absolute Easiest Way to Debug Node.js — with VS Code
- Let's try setting that up together
-
Use your Chrome Browser as your debugger
node --inspect-brk filename.js
- Open in Chrome: chrome://inspect
-
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%
-
⚠️ 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.