node:console

Node.js console module, resolvable via both ESM import and CommonJS require. The module re-exports the realm's global console — graal-js already ships an implementation, so wrapping preserves 1:1 behaviour and identity:

javascript
require("node:console") === globalThis.console;   // → true

Method surface

All 19 methods from the WebIDL namespace are present and callable:
Present in graal-js globalFilled in by this module
log, info, warn, error, debugtrace — single output: Trace: + stack frames, with the shim's own frame stripped so the stack starts at the caller (matches Node)
dir, clear, assertdirxml — alias for log
count, countReset, group, groupCollapsed, groupEndtable — full Node-shaped ASCII table with (index) column and box-drawing borders
time, timeEnd, timeLog

console.table

Renders the same three input shapes Node supports:

  • Array of objects — columns are the union of keys; index column shows 0..n.
  • Array of primitives — single Values column; index column shows 0..n.
  • Object of objects — rows keyed by outer keys; columns are union of inner keys.
  • Anything else falls back to log(data).

Values are inspected with Node-style rules: strings are single-quoted, numbers/ booleans/null/undefined rendered raw, functions shown as [Function: ], nested objects/arrays collapsed to [Object]/[Array].

javascript
c.table([{ a: 1, b: 'x' }, { a: 2, b: 'y' }]);
// ┌─────────┬───┬─────┐
// │ (index) │ a │  b  │
// ├─────────┼───┼─────┤
// │    0    │ 1 │ 'x' │
// │    1    │ 2 │ 'y' │
// └─────────┴───┴─────┘

The three shims are installed once on first module resolution and are idempotent — re-requiring node:console does not re-patch.

Formatting

log, info, warn, error, and debug apply util.format-style substitution when the first argument is a format string: %s, %d, %i, %f, %j, %o, %O, and %% are honoured, and any remaining arguments are appended. The same formatting applies to Console instances (below).

console.Console

The Console constructor is exported and creates an independent console that writes to the streams you supply:

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

const out = new Console(process.stdout, process.stderr);
out.log("goes to fd 1");
new Console(stdout[, stderr][, ignoreErrors]) and the options form new Console({ stdout, stderr }) are both supported; a stdout that is not a writable stream throws a TypeError.

Example

javascript
const c = require("node:console");

c.log("hello");              // → hello
c.trace("boom");             // → Trace: boom\n  at <stack frames>
c.table([{a:1,b:2}]);        // → ASCII table with an (index) column

// Named-import form
import { log, error } from "node:console";
log("fast-path destructuring");

Notes

  • Mutations to globalThis.console (adding methods, replacing existing ones) are visible through require("node:console") and vice-versa, since they are the same object.

See also

  • Node.js upstream: