GitHub - huksley/nodebugger: Command line nodejs debugger

2 min read Original article ↗

nodebugger

CLI to inspect running Node.js processes via V8 Inspector Protocol.

Install

npm install -g nodebugger

Usage

nodebugger [port] [command] [args]

Start your Node.js app with inspector enabled:

node --inspect app.js
node --inspect=9230 app.js

Interactive mode:

nodebugger              # REPL on default port 9229
nodebugger 9230         # REPL on port 9230

Single command mode:

nodebugger eval "1+1"
nodebugger 9230 eval "process.pid"
nodebugger stack
nodebugger 9230 stack

Commands

Command Short Description
eval <expr> e Evaluate JS expression in target process
stack s Capture stack trace (pauses → dumps → resumes)
pause p Pause execution
resume r Resume execution
exit q Disconnect and exit
help ? Show commands

Unknown input is treated as eval.

Examples

> process.env.NODE_ENV
"production"

> Object.keys(require.cache).length
42

> stack
Stack Trace:
  0: processTicksAndRejections (node:internal/process/task_queues:95:5)
  1: runNextTicks (node:internal/process/task_queues:64:3)

> global.DEBUG = true
true

Programmatic API

import { Inspector } from 'nodebugger';

const inspector = new Inspector(9229);
await inspector.connect();

const result = await inspector.eval('process.memoryUsage()');
console.log(result);

const stack = await inspector.getStackTrace();
console.log(stack);

await inspector.disconnect();

API

  • new Inspector(port?, options?) - Create inspector instance
  • connect() - Connect to target process
  • eval(expression) - Evaluate JS expression
  • pause() - Pause execution
  • resume() - Resume execution
  • getStackTrace() - Get current stack trace (pauses if needed)
  • disconnect() - Clean disconnect

Links

License

MIT