Skip to content

Instantly share code, notes, and snippets.

@mfrancois3k
Forked from gnmonsour/debuggingNode.md
Created June 19, 2022 03:08
Show Gist options
  • Save mfrancois3k/dfc8778cd9c521b3d062d366b33b4881 to your computer and use it in GitHub Desktop.
Save mfrancois3k/dfc8778cd9c521b3d062d366b33b4881 to your computer and use it in GitHub Desktop.
debugging with node

How to debug nodejs code

  1. You will get a debug> prompt paused at a debugger breakpoint.
 $> node inspect app.js

Navigate with the following:

  • c will continue to next debuggerstatement or end
  • n runs the next code line
  • s steps into a function
  • o steps out of the current function

You can inspect objects by entering repl mode

debug>repl

Ctrl-C to return from repl to debug mode

NOTE: this is the least eloquent manner, with the following you get access to chrome devtools for a debugging enviroment

  1. You can inspect long running processes s/a servers with this.
$> node --inspect app.js

You likely will need a debugger statement to break at. You are likely to not use this.

  1. The following will open the debugging environment at the first line of code. It will be what you most likely should use
$> node --inspect-brk app.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment