node:console API Reference

Console methods, formatting, and custom Console instances

require("node:console") and globalThis.console return the same object. The module also exports Console for writing to custom streams.

import console, { Console } from "node:console";

console.log("value=%d", 2);
console.table([{ a: 1, b: "x" }]);

const custom = new Console(process.stdout, process.stderr);
custom.warn("written to stderr");

The usual methods are available: log, info, warn, error, debug, dir, trace, table, assert, clear, counters, groups, and timers. Formatting supports %s, %d, %i, %f, %j, %o, %O, and %%.

console.table supports arrays and objects and renders an ASCII table. Its spacing and alignment are implementation-defined; do not parse the rendered text.

Replacing process.stdout.write or process.stderr.write also intercepts the corresponding global console output.