node:console
Node-compatible Console class and formatted console logging utilities
(node:console).
Available in both vjs and vjs-lite runtimes. Enabled by default unless
--no-node-compat is passed. Never mutates globalThis.console — import
explicitly from "node:console".
import ... from "node:console"
node-compat (enabled by default; disable with --no-node-compat)Example
Section titled “Example”import { Console, log, time, timeEnd } from "node:console";
time("work");log("hello from node:console");timeEnd("work");assertv0.0.0-alpha.2value is falsy.clearv0.0.0-alpha.2countv0.0.0-alpha.2label (default "default").countResetv0.0.0-alpha.2label (default "default").debugv0.0.0-alpha.2dirv0.0.0-alpha.2item using options and write to stdout.errorv0.0.0-alpha.2groupv0.0.0-alpha.2label.groupCollapsedv0.0.0-alpha.2group().groupEndv0.0.0-alpha.2infov0.0.0-alpha.2logv0.0.0-alpha.2tablev0.0.0-alpha.2tabularData as a table and write to stdout.timev0.0.0-alpha.2label (default "default").timeEndv0.0.0-alpha.2label and log elapsed time to stdout.timeLogv0.0.0-alpha.2label along with data.tracev0.0.0-alpha.2"Trace: ..." and the current stack trace to stderr.warnv0.0.0-alpha.2ConsoleWritableStreamv0.0.0-alpha.2new Console(stdout, stderr).ConsoleInspectOptionsv0.0.0-alpha.2dir() and new Console({ inspectOptions }).ConsoleConstructorOptionsv0.0.0-alpha.2new Console(options).Functions
Section titled “Functions”assert
Section titled “assert”export function assert(value: unknown, message?: string, ...optionalParams: unknown[]): void;
Write an assertion failure message to stderr when value is falsy.
| Name | Type | Description |
|---|---|---|
value | unknown | — |
message optional | string | — |
...optionalParams | unknown[] | — |
voidexport function clear(): void;
Clear console output when connected to a TTY.
voidexport function count(label?: string): void;
Increment and log the invocation count for label (default "default").
| Name | Type | Description |
|---|---|---|
label optional | string | — |
voidcountReset
Section titled “countReset”export function countReset(label?: string): void;
Reset the invocation counter for label (default "default").
| Name | Type | Description |
|---|---|---|
label optional | string | — |
voidexport function debug(message?: unknown, ...optionalParams: unknown[]): void;
Format and write debug output to stdout.
| Name | Type | Description |
|---|---|---|
message optional | unknown | — |
...optionalParams | unknown[] | — |
voidexport function dir(item?: unknown, options?: ConsoleInspectOptions): void;
Inspect item using options and write to stdout.
| Name | Type | Description |
|---|---|---|
item optional | unknown | — |
options optional | ConsoleInspectOptions | — |
voidexport function error(message?: unknown, ...optionalParams: unknown[]): void;
Format and write error output to stderr.
| Name | Type | Description |
|---|---|---|
message optional | unknown | — |
...optionalParams | unknown[] | — |
voidexport function group(...label: unknown[]): void;
Increase indentation for subsequent log output and optionally print label.
| Name | Type | Description |
|---|---|---|
...label | unknown[] | — |
voidgroupCollapsed
Section titled “groupCollapsed”export function groupCollapsed(...label: unknown[]): void;
Alias for group().
| Name | Type | Description |
|---|---|---|
...label | unknown[] | — |
voidgroupEnd
Section titled “groupEnd”export function groupEnd(): void;
Decrease the current group indentation level.
voidexport function info(message?: unknown, ...optionalParams: unknown[]): void;
Format and write informational output to stdout.
| Name | Type | Description |
|---|---|---|
message optional | unknown | — |
...optionalParams | unknown[] | — |
voidexport function log(message?: unknown, ...optionalParams: unknown[]): void;
Format and write standard output to stdout.
| Name | Type | Description |
|---|---|---|
message optional | unknown | — |
...optionalParams | unknown[] | — |
voidexport function table(tabularData: unknown, properties?: readonly string[]): void;
Format tabularData as a table and write to stdout.
| Name | Type | Description |
|---|---|---|
tabularData | unknown | — |
properties optional | readonly string[] | — |
voidexport function time(label?: string): void;
Start a timer keyed by label (default "default").
| Name | Type | Description |
|---|---|---|
label optional | string | — |
voidtimeEnd
Section titled “timeEnd”export function timeEnd(label?: string): void;
Stop timer label and log elapsed time to stdout.
| Name | Type | Description |
|---|---|---|
label optional | string | — |
voidtimeLog
Section titled “timeLog”export function timeLog(label?: string, ...data: unknown[]): void;
Log current elapsed time for active timer label along with data.
| Name | Type | Description |
|---|---|---|
label optional | string | — |
...data | unknown[] | — |
voidexport function trace(message?: unknown, ...optionalParams: unknown[]): void;
Write "Trace: ..." and the current stack trace to stderr.
| Name | Type | Description |
|---|---|---|
message optional | unknown | — |
...optionalParams | unknown[] | — |
voidexport function warn(message?: unknown, ...optionalParams: unknown[]): void;
Format and write warning output to stderr.
| Name | Type | Description |
|---|---|---|
message optional | unknown | — |
...optionalParams | unknown[] | — |
voidClasses
Section titled “Classes”Console
Section titled “Console”export class Console {
constructor(
stdout: ConsoleWritableStream,
stderr?: ConsoleWritableStream,
ignoreErrors?: boolean,
);
constructor(options: ConsoleConstructorOptions);
assert(value: unknown, message?: string, ...optionalParams: unknown[]): void;
clear(): void;
count(label?: string): void;
countReset(label?: string): void;
debug(message?: unknown, ...optionalParams: unknown[]): void;
dir(item?: unknown, options?: ConsoleInspectOptions): void;
error(message?: unknown, ...optionalParams: unknown[]): void;
group(...label: unknown[]): void;
groupCollapsed(...label: unknown[]): void;
groupEnd(): void;
info(message?: unknown, ...optionalParams: unknown[]): void;
log(message?: unknown, ...optionalParams: unknown[]): void;
table(tabularData: unknown, properties?: readonly string[]): void;
time(label?: string): void;
timeEnd(label?: string): void;
timeLog(label?: string, ...data: unknown[]): void;
trace(message?: unknown, ...optionalParams: unknown[]): void;
warn(message?: unknown, ...optionalParams: unknown[]): void;
}
Configurable Console logger writing formatted output to stdout and stderr streams.
constructor(
stdout: ConsoleWritableStream,
stderr?: ConsoleWritableStream,
ignoreErrors?: boolean,
);
constructor(options: ConsoleConstructorOptions);
Construct a Console writing to stdout and optional stderr.
new Console(stdout, stderr?, ignoreErrors?)| Name | Type | Description |
|---|---|---|
stdout | ConsoleWritableStream | Stream for standard output methods. |
stderr optional | ConsoleWritableStream | Optional stream for warning and error output (defaults to stdout). |
ignoreErrors optional | boolean | Ignore underlying write failures when true. |
new Console(options)Construct a Console from an options object.
| Name | Type | Description |
|---|---|---|
options | ConsoleConstructorOptions | Stream and formatting configuration. |
Console.assert
Section titled “Console.assert”assert(value: unknown, message?: string, ...optionalParams: unknown[]): void;
Log an assertion failure to stderr when value is falsy.
| Name | Type | Description |
|---|---|---|
value | unknown | — |
message optional | string | — |
...optionalParams | unknown[] | — |
voidConsole.clear
Section titled “Console.clear”clear(): void;
Clear console output when supported by the target stream.
voidConsole.count
Section titled “Console.count”count(label?: string): void;
Increment and log an invocation counter for label.
| Name | Type | Description |
|---|---|---|
label optional | string | — |
voidConsole.countReset
Section titled “Console.countReset”countReset(label?: string): void;
Reset the invocation counter for label.
| Name | Type | Description |
|---|---|---|
label optional | string | — |
voidConsole.debug
Section titled “Console.debug”debug(message?: unknown, ...optionalParams: unknown[]): void;
Format and write debug arguments to stdout.
| Name | Type | Description |
|---|---|---|
message optional | unknown | — |
...optionalParams | unknown[] | — |
voidConsole.dir
Section titled “Console.dir”dir(item?: unknown, options?: ConsoleInspectOptions): void;
Inspect item with optional formatting options and write to stdout.
| Name | Type | Description |
|---|---|---|
item optional | unknown | — |
options optional | ConsoleInspectOptions | — |
voidConsole.error
Section titled “Console.error”error(message?: unknown, ...optionalParams: unknown[]): void;
Format and write error arguments to stderr.
| Name | Type | Description |
|---|---|---|
message optional | unknown | — |
...optionalParams | unknown[] | — |
voidConsole.group
Section titled “Console.group”group(...label: unknown[]): void;
Increase indentation level and optionally log a group header.
| Name | Type | Description |
|---|---|---|
...label | unknown[] | — |
voidConsole.groupCollapsed
Section titled “Console.groupCollapsed”groupCollapsed(...label: unknown[]): void;
Alias for group().
| Name | Type | Description |
|---|---|---|
...label | unknown[] | — |
voidConsole.groupEnd
Section titled “Console.groupEnd”groupEnd(): void;
Decrease the active group indentation level.
voidConsole.info
Section titled “Console.info”info(message?: unknown, ...optionalParams: unknown[]): void;
Format and write informational arguments to stdout.
| Name | Type | Description |
|---|---|---|
message optional | unknown | — |
...optionalParams | unknown[] | — |
voidConsole.log
Section titled “Console.log”log(message?: unknown, ...optionalParams: unknown[]): void;
Format and write arguments to stdout.
| Name | Type | Description |
|---|---|---|
message optional | unknown | — |
...optionalParams | unknown[] | — |
voidConsole.table
Section titled “Console.table”table(tabularData: unknown, properties?: readonly string[]): void;
Format tabularData as an ASCII table and write to stdout.
| Name | Type | Description |
|---|---|---|
tabularData | unknown | — |
properties optional | readonly string[] | — |
voidConsole.time
Section titled “Console.time”time(label?: string): void;
Start a named high-resolution timer.
| Name | Type | Description |
|---|---|---|
label optional | string | — |
voidConsole.timeEnd
Section titled “Console.timeEnd”timeEnd(label?: string): void;
Stop a named timer and log elapsed duration to stdout.
| Name | Type | Description |
|---|---|---|
label optional | string | — |
voidConsole.timeLog
Section titled “Console.timeLog”timeLog(label?: string, ...data: unknown[]): void;
Log elapsed duration for an active timer without stopping it.
| Name | Type | Description |
|---|---|---|
label optional | string | — |
...data | unknown[] | — |
voidConsole.trace
Section titled “Console.trace”trace(message?: unknown, ...optionalParams: unknown[]): void;
Write a formatted stack trace to stderr.
| Name | Type | Description |
|---|---|---|
message optional | unknown | — |
...optionalParams | unknown[] | — |
voidConsole.warn
Section titled “Console.warn”warn(message?: unknown, ...optionalParams: unknown[]): void;
Format and write warning arguments to stderr.
| Name | Type | Description |
|---|---|---|
message optional | unknown | — |
...optionalParams | unknown[] | — |
voidInterfaces
Section titled “Interfaces”ConsoleWritableStream
Section titled “ConsoleWritableStream”export interface ConsoleWritableStream {
write(chunk: string | Uint8Array): boolean | void;
}
Minimal writable stream interface accepted by new Console(stdout, stderr).
ConsoleWritableStream.write
Section titled “ConsoleWritableStream.write”write(chunk: string | Uint8Array): boolean | void;
Write formatted text or bytes to the destination stream.
| Name | Type | Description |
|---|---|---|
chunk | string | Uint8Array | Formatted string or byte chunk. |
boolean | void — boolean or void.ConsoleInspectOptions
Section titled “ConsoleInspectOptions”export interface ConsoleInspectOptions {
showHidden?: boolean;
depth?: number | null;
colors?: boolean;
customInspect?: boolean;
showProxy?: boolean;
maxArrayLength?: number | null;
maxStringLength?: number | null;
breakLength?: number;
compact?: boolean | number;
sorted?: boolean | ((a: string, b: string) => number);
getters?: boolean | "get" | "set";
}
Formatting options accepted by dir() and new Console({ inspectOptions }).
| Property | Type | Description | Since |
|---|---|---|---|
showHidden optional | boolean | Include non-enumerable properties when inspecting objects. | v0.0.0-alpha.2 |
depth optional | number | null | Maximum recursion depth (null for unlimited). | v0.0.0-alpha.2 |
colors optional | boolean | Enable ANSI color output. | v0.0.0-alpha.2 |
customInspect optional | boolean | Invoke custom inspect symbols when available. | v0.0.0-alpha.2 |
showProxy optional | boolean | Inspect Proxy targets and handlers. | v0.0.0-alpha.2 |
maxArrayLength optional | number | null | Maximum array elements formatted. | v0.0.0-alpha.2 |
maxStringLength optional | number | null | Maximum string characters formatted. | v0.0.0-alpha.2 |
breakLength optional | number | Preferred line wrap column width. | v0.0.0-alpha.2 |
compact optional | boolean | number | Compact object formatting threshold. | v0.0.0-alpha.2 |
sorted optional | boolean | ((a: string, b: string) => number) | Sort object keys alphabetically or with a comparator. | v0.0.0-alpha.2 |
getters optional | boolean | "get" | "set" | Inspect getter properties. | v0.0.0-alpha.2 |
ConsoleConstructorOptions
Section titled “ConsoleConstructorOptions”export interface ConsoleConstructorOptions {
stdout: ConsoleWritableStream;
stderr?: ConsoleWritableStream;
ignoreErrors?: boolean;
colorMode?: boolean | "auto";
inspectOptions?: ConsoleInspectOptions;
groupIndentation?: number;
}
Configuration object accepted by new Console(options).
| Property | Type | Description | Since |
|---|---|---|---|
stdout | ConsoleWritableStream | Destination stream for log, info, debug, dir, table, and count. | v0.0.0-alpha.2 |
stderr optional | ConsoleWritableStream | Destination stream for warn, error, trace, and assert failures (defaults to stdout). | v0.0.0-alpha.2 |
ignoreErrors optional | boolean | Suppress stream write errors when writing to stdout or stderr (default true). | v0.0.0-alpha.2 |
colorMode optional | boolean | "auto" | ANSI color mode (true, false, or "auto"). | v0.0.0-alpha.2 |
inspectOptions optional | ConsoleInspectOptions | Default inspection options applied to object arguments. | v0.0.0-alpha.2 |
groupIndentation optional | number | Number of spaces per group() indentation level (default 2). | v0.0.0-alpha.2 |
Default Export
Section titled “Default Export”default export
Section titled “default export”const _default: {
/** `Console` constructor. @since 0.0.0-alpha.2 */
Console: typeof Console;
/** Assert truthiness. @since 0.0.0-alpha.2 */
assert: typeof assert;
/** Clear output. @since 0.0.0-alpha.2 */
clear: typeof clear;
/** Increment named counter. @since 0.0.0-alpha.2 */
count: typeof count;
/** Reset named counter. @since 0.0.0-alpha.2 */
countReset: typeof countReset;
/** Write debug output. @since 0.0.0-alpha.2 */
debug: typeof debug;
/** Inspect a value. @since 0.0.0-alpha.2 */
dir: typeof dir;
/** Write error output. @since 0.0.0-alpha.2 */
error: typeof error;
/** Start an indented group. @since 0.0.0-alpha.2 */
group: typeof group;
/** Start a collapsed group. @since 0.0.0-alpha.2 */
groupCollapsed: typeof groupCollapsed;
/** End the current group. @since 0.0.0-alpha.2 */
groupEnd: typeof groupEnd;
/** Write informational output. @since 0.0.0-alpha.2 */
info: typeof info;
/** Write standard output. @since 0.0.0-alpha.2 */
log: typeof log;
/** Print tabular data. @since 0.0.0-alpha.2 */
table: typeof table;
/** Start a timer. @since 0.0.0-alpha.2 */
time: typeof time;
/** Stop a timer and print elapsed time. @since 0.0.0-alpha.2 */
timeEnd: typeof timeEnd;
/** Print elapsed time for an active timer. @since 0.0.0-alpha.2 */
timeLog: typeof timeLog;
/** Print a stack trace. @since 0.0.0-alpha.2 */
trace: typeof trace;
/** Write warning output. @since 0.0.0-alpha.2 */
warn: typeof warn;
};
export default _default;
Default export object providing the node:console API.
