GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Main page
  • Get MediaWiki
  • Get extensions
  • Tech blog
  • Contribute
  • User help
  • FAQ
  • Technical manual
  • Support desk
  • Communication
  • Developer portal
  • Code statistics
  • Community portal
  • Recent changes

This view

  • Original page
  • New address

GeezerVison is showing www.mediawiki.org — Node.js debugging - MediaWiki

Stack overflows

It used to be hard to debug stack overflows in node, as it would just bomb without producing a stack trace. This has thankfully changed with node 0.11. It also helps to increase the stack depth to spot larger recursions:

$ node --stack-trace-limit=1000 <script.js>

Chrome DevTools

See also: Debugging Node.js Nightlies with Chrome DevTools. Available as of Node v6.3.0.

$ node --inspect script.js

  To start debugging, open the following URL in Chrome:
  chrome-devtools://devtools/remote/serve_file/@../inspector.html?..

For command-line scripts that run immediately, you may want to use --debug-brk so that you have an opportunity to start a Profile in the Dev Tools, for example. (Starting a CPU profiler will automatically resume script execution).

For services you'll usually want to omit --debug-brk so that it won't time out when creating workers. Attach your debugger in Chrome, start a Profile, and then make requests to your service. Here's an example profiling Parsoid. We set worker count to 1 as each process gets its own debugger.

$ node --inspect ./node_modules/.bin/service-runner -n 1

  Debugger listening on port 9229.
  To start debugging, open the following URL in Chrome:
    chrome-devtools://devtools/remote/serve_file/@../inspector.html?..&ws=localhost:9229/node

  Debugger listening on port 5859.
  To start debugging, open the following URL in Chrome:
    chrome-devtools://devtools/remote/serve_file/@../inspector.html?..&ws=localhost:5859/node

Made a request to "http://localhost:8000/localhost/v3/page/html/Main_Page" and stopped the debugger. Example flame chart: https://i.imgur.com/HshfDOx.png

Profiling

A good tool for profiling nodejs applications is the combination of nodegrind and kcachegrind.

Quick start:

$ npm install -g nodegrind
$ nodegrind <script.js>
  Profile written to "callgrind.out.8004"
  Try `kcachegrind "callgrind.out.8004"`
$ kcachegrind callgrind.out.8004
Retrieved from "https://www.mediawiki.org/w/index.php?title=Node.js_debugging&oldid=7489874"
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.