debugging node code

if we want to run node in a debug mode we can simply run

node debug <nodeScriptFileName>

And if we put debugger command inside the script then it will stop in those location and allow us to choose what to do:

  • for continue.

    • cont
    • c
    • next
    • n
  • for step in
    • step
  • for step out
    • out
    • o
  • for restarting

    • restart
    • r
  • output the backtrace for the current execution

    • backtrace
    • bt
  • for evaluation and executing code:
    • repl

we can press p anytime to pause the script.

If we the script already started to run then we need to get its process id and the debug it by running the following:

node debug -p <processId>

Anther option is to use node-inspector.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s