Bun

Node.js module

inspector

Not implemented in Bun

Not implemented. Debugging is typically done via standard debugger protocols (like Chrome DevTools Protocol) connected to the Bun process itself, not via this module.

  • namespace Network

    • function put(
      url: string,
      data: string
      ): void;

      This feature is only available with the --experimental-inspector-network-resource flag enabled.

      The inspector.NetworkResources.put method is used to provide a response for a loadNetworkResource request issued via the Chrome DevTools Protocol (CDP). This is typically triggered when a source map is specified by URL, and a DevTools frontend—such as Chrome—requests the resource to retrieve the source map.

      This method allows developers to predefine the resource content to be served in response to such CDP requests.

      const inspector = require('node:inspector');
      // By preemptively calling put to register the resource, a source map can be resolved when
      // a loadNetworkResource request is made from the frontend.
      async function setNetworkResources() {
        const mapUrl = 'http://localhost:3000/dist/app.js.map';
        const tsUrl = 'http://localhost:3000/src/app.ts';
        const distAppJsMap = await fetch(mapUrl).then((res) => res.text());
        const srcAppTs = await fetch(tsUrl).then((res) => res.text());
        inspector.NetworkResources.put(mapUrl, distAppJsMap);
        inspector.NetworkResources.put(tsUrl, srcAppTs);
      };
      setNetworkResources().then(() => {
        require('./dist/app');
      });
      

      For more details, see the official CDP documentation: Network.loadNetworkResource

  • class Session

    The inspector.Session is used for dispatching messages to the V8 inspector back-end and receiving message responses and notifications.

  • An object to send messages to the remote inspector console.

  • function close(): void;

    Deactivate the inspector. Blocks until there are no active connections.

  • function open(
    port?: number,
    host?: string,
    wait?: boolean
    ): Disposable;

    Activate inspector on host and port. Equivalent to node --inspect=[[host:]port], but can be done programmatically after node has started.

    If wait is true, will block until a client has connected to the inspect port and flow control has been passed to the debugger client.

    See the security warning regarding the host parameter usage.

    @param port

    Port to listen on for inspector connections. Defaults to what was specified on the CLI.

    @param host

    Host to listen on for inspector connections. Defaults to what was specified on the CLI.

    @param wait

    Block until a client has connected. Defaults to what was specified on the CLI.

    @returns

    Disposable that calls inspector.close().

  • function url(): undefined | string;

    Return the URL of the active inspector, or undefined if there is none.

    $ node --inspect -p 'inspector.url()'
    Debugger listening on ws://127.0.0.1:9229/166e272e-7a30-4d09-97ce-f1c012b43c34
    For help, see: https://nodejs.org/en/docs/inspector
    ws://127.0.0.1:9229/166e272e-7a30-4d09-97ce-f1c012b43c34
    
    $ node --inspect=localhost:3000 -p 'inspector.url()'
    Debugger listening on ws://localhost:3000/51cf8d0e-3c36-4c59-8efd-54519839e56a
    For help, see: https://nodejs.org/en/docs/inspector
    ws://localhost:3000/51cf8d0e-3c36-4c59-8efd-54519839e56a
    
    $ node -p 'inspector.url()'
    undefined
    
  • function waitForDebugger(): void;

    Blocks until a client (existing or connected later) has sent Runtime.runIfWaitingForDebugger command.

    An exception will be thrown if there is no active inspector.

Type definitions