Node.js Debugger
A debugger can inspect and control the process it attaches to. Treat its listener as a powerful development interface rather than a public status endpoint.
How it works
This example opens the inspector only in its own short-lived child and requests an available loopback port. It checks that the child reports an inspector URL without publishing that URL or pausing indefinitely at startup. For manual debugging, set breakpoints in the relevant source and inspect actual values and call stacks. Profilers and heap snapshots answer other diagnostic questions and can themselves affect timing and contain sensitive process data.
Run the code
Run this example locally with Node.js. The exact sources are reviewed on Node 22.15.1 and Node 24.22.1 unless a specialised lab states otherwise. Save the complete source as debugger.mjs in a separate empty exercises folder and run node debugger.mjs. There is no Node.js browser runner on Bhylu; the plain JavaScript playground does not provide these filesystem, server or process APIs.
Download the complete source. Ordinary Node scripts need no Apache, PHP or MySQL service. File examples own their temporary folders; network fixtures use loopback and available temporary ports.
Example
import { spawnSync } from 'node:child_process';
const result = spawnSync(
process.execPath,
[
'--inspect=127.0.0.1:0',
'--input-type=module',
'-e',
"import inspector from 'node:inspector'; console.log(inspector.url().startsWith('ws://127.0.0.1:'));",
],
{ encoding: 'utf8', timeout: 10000, windowsHide: true },
);
if (result.status !== 0) throw new Error('Debugger fixture failed');
console.log(result.stdout.trim());
Expected result
true
The debugger is attached only to the owned fixture process and disappears when it exits. This is an execution check of inspector startup, not a complete interactive debugging session or a production incident-response exercise.
Use the Node.js API reference for the precise version contract.