5/12/2013 - 12:00 PM

Debugging & Profiling Node.js

This is a maintained listing of all the different ways to debug and profile Node.js applications. If there is something missing or an improvement, post a comment! :)

Interactive Stack Traces with traceGL - Shareware

  1. Guide here

Profiling with Profiler

  1. Install globally npm install -g profiler
  2. Start your process with node --prof this will create a v8.log file
  3. Build nprof by running /Users/balupton/.nvm/v0.8.22/lib/node_modules/profiler/tools/build-nprof
  4. Run /Users/balupton/.nvm/v0.8.22/lib/node_modules/profiler/nprof this will read the v8.log profile and give you nice ouput

CPU and Memory Profiling with NodeTime

  1. Install to your app npm install nodetime
  2. Include in your app require('nodetime').profile()
  3. Follow the instructions it will output to console

Wekit Inspector Debugging with Node Inspector

  1. No longer supported unfortunately, however usually works if you downgrade: npm install -g node-inspector@0.1.10
  2. Run your app in debug mode: node --debug-brk your/node/program.js
  3. In another terminal window run node-inspector: node-inspector
  4. Open

Webkit Inspector Profiling with Node Webkit Agent

  1. Install to your app npm install webkit-devtools-agent
  2. Include in your app agent = require('webkit-devtools-agent')
  3. Activate the agent: kill -SIGUSR2 <your node process id>
  4. Access the agent via the appropriate link

Flamegraphs with Dtrace and StackVis

  1. Only supported on SmartOS

Benchmark with Apache Bench

  1. Benchmark a ton of requests to your server ab -n 100000 -c 1