Skip to content
VaelJS Blog

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"
Since v0.0.0-alpha.2 vjs (V8) vjs-lite (QuickJS)
Cargo feature: node-compat (enabled by default; disable with --no-node-compat)
import { Console, log, time, timeEnd } from "node:console";
time("work");
log("hello from node:console");
timeEnd("work");
API Symbols
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function assert(value: unknown, message?: string, ...optionalParams: unknown[]): void;

Write an assertion failure message to stderr when value is falsy.

Parameters
NameTypeDescription
valueunknown—
message optionalstring—
...optionalParamsunknown[]—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function clear(): void;

Clear console output when connected to a TTY.

Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function count(label?: string): void;

Increment and log the invocation count for label (default "default").

Parameters
NameTypeDescription
label optionalstring—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function countReset(label?: string): void;

Reset the invocation counter for label (default "default").

Parameters
NameTypeDescription
label optionalstring—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function debug(message?: unknown, ...optionalParams: unknown[]): void;

Format and write debug output to stdout.

Parameters
NameTypeDescription
message optionalunknown—
...optionalParamsunknown[]—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function dir(item?: unknown, options?: ConsoleInspectOptions): void;

Inspect item using options and write to stdout.

Parameters
NameTypeDescription
item optionalunknown—
options optionalConsoleInspectOptions—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function error(message?: unknown, ...optionalParams: unknown[]): void;

Format and write error output to stderr.

Parameters
NameTypeDescription
message optionalunknown—
...optionalParamsunknown[]—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function group(...label: unknown[]): void;

Increase indentation for subsequent log output and optionally print label.

Parameters
NameTypeDescription
...labelunknown[]—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function groupCollapsed(...label: unknown[]): void;

Alias for group().

Parameters
NameTypeDescription
...labelunknown[]—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function groupEnd(): void;

Decrease the current group indentation level.

Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function info(message?: unknown, ...optionalParams: unknown[]): void;

Format and write informational output to stdout.

Parameters
NameTypeDescription
message optionalunknown—
...optionalParamsunknown[]—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function log(message?: unknown, ...optionalParams: unknown[]): void;

Format and write standard output to stdout.

Parameters
NameTypeDescription
message optionalunknown—
...optionalParamsunknown[]—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function table(tabularData: unknown, properties?: readonly string[]): void;

Format tabularData as a table and write to stdout.

Parameters
NameTypeDescription
tabularDataunknown—
properties optionalreadonly string[]—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function time(label?: string): void;

Start a timer keyed by label (default "default").

Parameters
NameTypeDescription
label optionalstring—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function timeEnd(label?: string): void;

Stop timer label and log elapsed time to stdout.

Parameters
NameTypeDescription
label optionalstring—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function timeLog(label?: string, ...data: unknown[]): void;

Log current elapsed time for active timer label along with data.

Parameters
NameTypeDescription
label optionalstring—
...dataunknown[]—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function trace(message?: unknown, ...optionalParams: unknown[]): void;

Write "Trace: ..." and the current stack trace to stderr.

Parameters
NameTypeDescription
message optionalunknown—
...optionalParamsunknown[]—
Returns
void
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function warn(message?: unknown, ...optionalParams: unknown[]): void;

Format and write warning output to stderr.

Parameters
NameTypeDescription
message optionalunknown—
...optionalParamsunknown[]—
Returns
void
classSince v0.0.0-alpha.2vjs & vjs-lite
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
constructor(
  stdout: ConsoleWritableStream,
  stderr?: ConsoleWritableStream,
  ignoreErrors?: boolean,
);
constructor(options: ConsoleConstructorOptions);

Construct a Console writing to stdout and optional stderr.

Overload 1 — new Console(stdout, stderr?, ignoreErrors?)
NameTypeDescription
stdoutConsoleWritableStreamStream for standard output methods.
stderr optionalConsoleWritableStreamOptional stream for warning and error output (defaults to stdout).
ignoreErrors optionalbooleanIgnore underlying write failures when true.
Overload 2 — new Console(options)

Construct a Console from an options object.

NameTypeDescription
optionsConsoleConstructorOptionsStream and formatting configuration.
Methods
methodSince v0.0.0-alpha.2
assert(value: unknown, message?: string, ...optionalParams: unknown[]): void;

Log an assertion failure to stderr when value is falsy.

Parameters
NameTypeDescription
valueunknown—
message optionalstring—
...optionalParamsunknown[]—
Returns
void
methodSince v0.0.0-alpha.2
clear(): void;

Clear console output when supported by the target stream.

Returns
void
methodSince v0.0.0-alpha.2
count(label?: string): void;

Increment and log an invocation counter for label.

Parameters
NameTypeDescription
label optionalstring—
Returns
void
methodSince v0.0.0-alpha.2
countReset(label?: string): void;

Reset the invocation counter for label.

Parameters
NameTypeDescription
label optionalstring—
Returns
void
methodSince v0.0.0-alpha.2
debug(message?: unknown, ...optionalParams: unknown[]): void;

Format and write debug arguments to stdout.

Parameters
NameTypeDescription
message optionalunknown—
...optionalParamsunknown[]—
Returns
void
methodSince v0.0.0-alpha.2
dir(item?: unknown, options?: ConsoleInspectOptions): void;

Inspect item with optional formatting options and write to stdout.

Parameters
NameTypeDescription
item optionalunknown—
options optionalConsoleInspectOptions—
Returns
void
methodSince v0.0.0-alpha.2
error(message?: unknown, ...optionalParams: unknown[]): void;

Format and write error arguments to stderr.

Parameters
NameTypeDescription
message optionalunknown—
...optionalParamsunknown[]—
Returns
void
methodSince v0.0.0-alpha.2
group(...label: unknown[]): void;

Increase indentation level and optionally log a group header.

Parameters
NameTypeDescription
...labelunknown[]—
Returns
void
methodSince v0.0.0-alpha.2
groupCollapsed(...label: unknown[]): void;

Alias for group().

Parameters
NameTypeDescription
...labelunknown[]—
Returns
void
methodSince v0.0.0-alpha.2
groupEnd(): void;

Decrease the active group indentation level.

Returns
void
methodSince v0.0.0-alpha.2
info(message?: unknown, ...optionalParams: unknown[]): void;

Format and write informational arguments to stdout.

Parameters
NameTypeDescription
message optionalunknown—
...optionalParamsunknown[]—
Returns
void
methodSince v0.0.0-alpha.2
log(message?: unknown, ...optionalParams: unknown[]): void;

Format and write arguments to stdout.

Parameters
NameTypeDescription
message optionalunknown—
...optionalParamsunknown[]—
Returns
void
methodSince v0.0.0-alpha.2
table(tabularData: unknown, properties?: readonly string[]): void;

Format tabularData as an ASCII table and write to stdout.

Parameters
NameTypeDescription
tabularDataunknown—
properties optionalreadonly string[]—
Returns
void
methodSince v0.0.0-alpha.2
time(label?: string): void;

Start a named high-resolution timer.

Parameters
NameTypeDescription
label optionalstring—
Returns
void
methodSince v0.0.0-alpha.2
timeEnd(label?: string): void;

Stop a named timer and log elapsed duration to stdout.

Parameters
NameTypeDescription
label optionalstring—
Returns
void
methodSince v0.0.0-alpha.2
timeLog(label?: string, ...data: unknown[]): void;

Log elapsed duration for an active timer without stopping it.

Parameters
NameTypeDescription
label optionalstring—
...dataunknown[]—
Returns
void
methodSince v0.0.0-alpha.2
trace(message?: unknown, ...optionalParams: unknown[]): void;

Write a formatted stack trace to stderr.

Parameters
NameTypeDescription
message optionalunknown—
...optionalParamsunknown[]—
Returns
void
methodSince v0.0.0-alpha.2
warn(message?: unknown, ...optionalParams: unknown[]): void;

Format and write warning arguments to stderr.

Parameters
NameTypeDescription
message optionalunknown—
...optionalParamsunknown[]—
Returns
void
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface ConsoleWritableStream {
  write(chunk: string | Uint8Array): boolean | void;
}

Minimal writable stream interface accepted by new Console(stdout, stderr).

Methods
methodSince v0.0.0-alpha.2
write(chunk: string | Uint8Array): boolean | void;

Write formatted text or bytes to the destination stream.

Parameters
NameTypeDescription
chunkstring | Uint8ArrayFormatted string or byte chunk.
Returns
boolean | void — boolean or void.
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
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 }).

Properties
PropertyTypeDescriptionSince
showHidden optionalbooleanInclude non-enumerable properties when inspecting objects.v0.0.0-alpha.2
depth optionalnumber | nullMaximum recursion depth (null for unlimited).v0.0.0-alpha.2
colors optionalbooleanEnable ANSI color output.v0.0.0-alpha.2
customInspect optionalbooleanInvoke custom inspect symbols when available.v0.0.0-alpha.2
showProxy optionalbooleanInspect Proxy targets and handlers.v0.0.0-alpha.2
maxArrayLength optionalnumber | nullMaximum array elements formatted.v0.0.0-alpha.2
maxStringLength optionalnumber | nullMaximum string characters formatted.v0.0.0-alpha.2
breakLength optionalnumberPreferred line wrap column width.v0.0.0-alpha.2
compact optionalboolean | numberCompact object formatting threshold.v0.0.0-alpha.2
sorted optionalboolean | ((a: string, b: string) => number)Sort object keys alphabetically or with a comparator.v0.0.0-alpha.2
getters optionalboolean | "get" | "set"Inspect getter properties.v0.0.0-alpha.2
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface ConsoleConstructorOptions {
  stdout: ConsoleWritableStream;
  stderr?: ConsoleWritableStream;
  ignoreErrors?: boolean;
  colorMode?: boolean | "auto";
  inspectOptions?: ConsoleInspectOptions;
  groupIndentation?: number;
}

Configuration object accepted by new Console(options).

Properties
PropertyTypeDescriptionSince
stdout ConsoleWritableStreamDestination stream for log, info, debug, dir, table, and count.v0.0.0-alpha.2
stderr optionalConsoleWritableStreamDestination stream for warn, error, trace, and assert failures (defaults to stdout).v0.0.0-alpha.2
ignoreErrors optionalbooleanSuppress stream write errors when writing to stdout or stderr (default true).v0.0.0-alpha.2
colorMode optionalboolean | "auto"ANSI color mode (true, false, or "auto").v0.0.0-alpha.2
inspectOptions optionalConsoleInspectOptionsDefault inspection options applied to object arguments.v0.0.0-alpha.2
groupIndentation optionalnumberNumber of spaces per group() indentation level (default 2).v0.0.0-alpha.2
defaultSince v0.0.0-alpha.2vjs & vjs-lite
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.