Inspector and debugging
Prerequisite: node-tracing-and-diagnostics-channels. Objective: Review safe local debugging plan. Local baseline: Node.js 22.16.0 on Linux, ESM. Each example is independent: save as main.mjs in a disposable directory and run node main.mjs. The author harness uses a five-second timeout. Static snippets are not ByteMind interactive execution.
How it works
For local manual debugging of an owned disposable script, node --inspect=127.0.0.1:9229 script.mjs starts a loopback inspector, while --inspect-brk pauses before user code begins. Check port availability and never expose an inspector to public or untrusted networks. An in-process inspector Session can issue protocol commands without opening a listening port. Disconnect in finally. Use fixed trusted protocol calls only; avoid evaluating user-supplied code. Breakpoints can change timing, so debugger behavior is not a concurrency performance measurement.
Check inspector state without opening a listener
import {url,Session} from 'node:inspector';import assert from 'node:assert/strict';assert.equal(url(),undefined);const session=new Session();session.connect();try{assert.equal(url(),undefined);console.log('in-process only');}finally{session.disconnect();}Expected output:
in-process onlySession.connect does not create an external inspector listener.
Observe explicit debugger setup choices as a model
function approve({owned,loopback,synthetic}){return owned&&loopback&&synthetic?'local lab':'reject';}for(const config of [{owned:true,loopback:true,synthetic:true},{owned:true,loopback:false,synthetic:true},{owned:false,loopback:true,synthetic:true}])console.log(approve(config));Expected output:
local labrejectrejectThe model is a checklist, not proof of actual isolation or network access control.
Common mistakes
Do not attach to an unknown production process, publish inspector URLs, or leave a session connected. A loopback listener is not an authentication mechanism.
Practice
Write a debugging plan that names the owned process, isolation, breakpoint, expected state and teardown without any public listener.
Reference candidate: node-inspector-and-debugging-lookup (route unverified). Documentation: https://nodejs.org/download/release/v22.16.0/docs/api/inspector.html, https://nodejs.org/docs/latest-v22.x/api/inspector.html. Exact-version documentation not retrieved in this batch; local fixture behavior tested.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Inspector and debugging — knowledge check
Apply the lesson to a fresh scenario and explain the evidence boundary.
Why should an inspector not listen publicly?
What does Session.connect do in the local fixture?
Do debugger pauses represent normal timing?