Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you debug Karma test runner? [duplicate]

How do I debug a Node.js server application?

Right now I'm mostly using alert debugging with print statements like this:

sys.puts(sys.inspect(someVariable));

There must be a better way to debug. I know that Google Chrome has a command-line debugger. Is this debugger available for Node.js as well?

like image 357
Fabian Jakobs Avatar asked Dec 15 '09 22:12

Fabian Jakobs


5 Answers

node-inspector could save the day! Use it from any browser supporting WebSocket. Breakpoints, profiler, livecoding, etc... It is really awesome.

Install it with:

npm install -g node-inspector

Then run:

node-debug app.js
like image 106
daralthus Avatar answered Oct 17 '22 12:10

daralthus


Debugging

  • Joyent's Guide
  • Debugger
  • Node Inspector
  • Visual Studio Code
  • Cloud9
  • Brackets

Profiling

  1. node --prof ./app.js
  2. node --prof-process ./the-generated-log-file

Heapdumps

  • node-heapdump with Chrome Developer Tools

Flamegraphs

  • 0x
  • jam3/devtool then Chrome Developer Tools Flame Charts
  • Dtrace and StackVis — Only supported on SmartOS
  • clinicjs

Tracing

  • Interactive Stack Traces with TraceGL

Logging

Libraries that output debugging information

  • Caterpillar
  • Tracer
  • scribbles

Libraries that enhance stack trace information

  • Longjohn

Benchmarking

  • Apache Bench: ab -n 100000 -c 1 http://127.0.0.1:9778/
  • wrk

Other

  • Trace
  • Vantage
  • Bugger
  • Google Tracing Framework
  • Paul Irish's Guide

Legacy

These use to work but are no longer maintained or no longer applicable to modern node versions.

  • https://github.com/bnoordhuis/node-profiler - replaced by built-in debugging
  • https://github.com/c4milo/node-webkit-agent - replaced by node inspector
  • https://nodetime.com/ - defunct
like image 34
balupton Avatar answered Oct 17 '22 13:10

balupton


The V8 debugger released as part of the Google Chrome Developer Tools can be used to debug Node.js scripts. A detailed explanation of how this works can be found in the Node.js GitHub wiki.

like image 23
Fabian Jakobs Avatar answered Oct 17 '22 13:10

Fabian Jakobs


Node has its own built in GUI debugger as of version 6.3 (using Chrome's DevTools)

Nodes builtin GUI debugger

Simply pass the inspector flag and you'll be provided with a URL to the inspector:

node --inspect server.js

You can also break on the first line by passing --inspect-brk instead.

like image 32
Alister Avatar answered Oct 17 '22 12:10

Alister


Node.js version 0.3.4+ has built-in debugging support.

node debug script.js

Manual: http://nodejs.org/api/debugger.html

like image 97
JulianW Avatar answered Oct 17 '22 13:10

JulianW