Introduction to Node.js Debugging

Julián Duque

Developer and Educator

@julian_duque

https://twitch.tv/julianduque

Challenges

  • Debugging Asynchronous workflows add a layer of complexity
  • Post-mortem debugging requires C/C++ tooling skills

How to debug Node.js Applications?

Choose your weapon!

Node Inspect

  • node --inspect
  • node --inspect-brk
  • Go to

    • chrome://inspect
  • Click on Inspect
 
 

Some tips

  • Start debug on a running process with:
    • kill -USR1 <pid>
  • Add a breakpoint to your code using:
    • debugger;

VSCode

Visual Studio Code supports the Node.js Debug protocol and it is a great tool for local and remote debugging.

ndb

It is a Chromium-based, standalone Node.js debugger by the ChromeLabs team with extra features that Chrome Inspector doesn't support out of the box

  • Child Process Debugging
  • Blackboxing
  • Edit in Place
$ npm install -g ndb

llnode

  • Useful for Post-Mortem debugging
  • Get useful information from a coredump after a crash
  • It helps to see the state of the Node process and debug the C/C++ native layer

 

  • npm install -g llnode
  • llnode `which node` -c core.dump

 

Useful npm modules

debug

Allows you to have a console-based debugger that can be enabled by using an environment variable

 

$ npm install debug

trace & clarify

trace: Augment your async stack traces

clarify: Removes node internals

$ npm i --save trace clarify

$ node --stack_trace_limit=100 -r trace server.js

$ node --stack_trace_limit=100 -r trace -r clarify server.js

Thank you!

Introduction to Node.js Debugging

By Julián Duque

Introduction to Node.js Debugging

Introduction to Node.js Debugging

  • 853