Bun

interface

Console

interface Console

  • readonly Console: {new (stdout: WritableStream, stderr?: WritableStream, ignoreErrors?: boolean) => Console; new (options: ConsoleOptions) => Console}
  • [Symbol.asyncIterator](): AsyncIterableIterator<string>;

    Asynchronously read lines from standard input (fd 0)

    for await (const line of console) {
      console.log(line);
    }
    
  • condition?: boolean,
    ...data: any[]
    ): void;
  • clear(): void;

    Clear the console

  • label?: string
    ): void;
    @param label

    label counter

  • label?: string
    ): void;
  • ...data: any[]
    ): void;
  • item?: any,
    options?: any
    ): void;
  • ...data: any[]
    ): void;
  • ...data: any[]
    ): void;

    Log to stderr in your terminal

    Appears in red

    @param data

    something to display

  • ...data: any[]
    ): void;

    Does nothing currently

  • ...data: any[]
    ): void;

    Does nothing currently

  • groupEnd(): void;

    Does nothing currently

  • ...data: any[]
    ): void;
  • ...data: any[]
    ): void;
  • label?: string
    ): void;

    This method does not display anything unless used in the inspector. The console.profile() method starts a JavaScript CPU profile with an optional label until profileEnd is called. The profile is then added to the Profile panel of the inspector.

    console.profile('MyLabel');
    // Some code
    console.profileEnd('MyLabel');
    // Adds the profile 'MyLabel' to the Profiles panel of the inspector.
    
  • label?: string
    ): void;

    This method does not display anything unless used in the inspector. Stops the current JavaScript CPU profiling session if one has been started and prints the report to the Profiles panel of the inspector. See profile for an example.

    If this method is called without a label, the most recently started profile is stopped.

  • tabularData?: any,
    properties?: string[]
    ): void;

    Try to construct a table with the columns of the properties of tabularData (or use properties) and rows of tabularData and log it. Falls back to just logging the argument if it can't be parsed as tabular.

    // These can't be parsed as tabular data
    console.table(Symbol());
    // Symbol()
    
    console.table(undefined);
    // undefined
    
    console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }]);
    // ┌────┬─────┬─────┐
    // │    │  a  │  b  │
    // ├────┼─────┼─────┤
    // │  0 │  1  │ 'Y' │
    // │  1 │ 'Z' │  2  │
    // └────┴─────┴─────┘
    
    console.table([{ a: 1, b: 'Y' }, { a: 'Z', b: 2 }], ['a']);
    // ┌────┬─────┐
    // │    │  a  │
    // ├────┼─────┤
    // │ 0  │  1  │
    // │ 1  │ 'Z' │
    // └────┴─────┘
    
    @param properties

    Alternate properties for constructing the table.

  • label?: string
    ): void;

    Begin a timer to log with console.timeEnd

    @param label

    The label to use for the timer

     console.time("how long????");
    for (let i = 0; i < 999999; i++) {
       // do stuff
       let x = i * i;
    }
    console.timeEnd("how long????");
    
  • label?: string
    ): void;

    End a timer to log with console.time

    @param label

    The label to use for the timer

     console.time("how long????");
    for (let i = 0; i < 999999; i++) {
     // do stuff
     let x = i * i;
    }
    console.timeEnd("how long????");
    
  • label?: string,
    ...data: any[]
    ): void;
  • label?: string
    ): void;
  • ...data: any[]
    ): void;
  • ...data: any[]
    ): void;
  • ...data: string | ArrayBuffer | ArrayBufferView<ArrayBufferLike>[]
    ): number;

    Write text or bytes to stdout

    Unlike console.log, this does no formatting and doesn't add a newline or spaces between arguments. You can pass it strings or bytes or any combination of the two.

    console.write("hello world!", "\n"); // "hello world\n"
    
    @param data

    The data to write

    @returns

    The number of bytes written

    This function is not available in the browser.