Skip to content

node:console

How Elide supports Node's console module and Console class: the inspector-only methods are absent and console.table formatting differs from Node.

On this page

node:console returns globalThis.console and exports Console for writing to other streams, as in Node’s console.

Example

js
// console.mjs
import { Console } from "node:console";
import { Writable } from "node:stream";

let captured = "";
const sink = new Writable({
  write(chunk, _encoding, done) {
    captured += chunk;
    done();
  },
});
const logger = new Console({ stdout: sink, stderr: sink });
logger.log("%s=%d", "retries", 3);
logger.error("failed");
logger.count("hits");
logger.count("hits");
process.stdout.write(captured);
utf-8 · js · Lines: 17

elide run console.mjs prints:

text
retries=3
failed
hits: 1
hits: 2
utf-8 · text · Lines: 4

Differences from Node

  • profile, profileEnd, timeStamp, context, and createTask are absent.
  • console.table spacing and alignment differ from Node; do not parse the output.

Reference

Status: Partial · 20 of 21 suite tests pass (95.2%) · since 1.1.0

Exports

ExportKindStatusNotes
log()functionFullPrints to stdout with newline
info()functionFullAlias for log()
warn()functionFullPrints to stderr with newline
error()functionFullPrints to stderr with newline
debug()functionFullPrints to stdout with newline
trace()functionFullPrints to stderr the string ‘Trace: ’ followed by a stack trace
dir()functionFullUses util.inspect() on obj and prints the resulting string to stdout
dirxml()functionFullAlias for log()
table()functionFullPrints a table representation of the data
clear()functionFullClears the console (when possible)
count()functionFullMaintains an internal counter and outputs the number of times count() has been called with the given label
countReset()functionFullResets the internal counter for the given label
group()functionFullIncreases indentation of subsequent lines by spaces for grouping
groupCollapsed()functionFullAlias for group()
groupEnd()functionFullDecreases indentation of subsequent lines by spaces for grouping
time()functionFullStarts a timer with a given label
timeEnd()functionFullStops a timer and prints elapsed time
timeLog()functionFullPrints the elapsed time for a running timer without stopping it
assert()functionFullWrites an error message to the console if the assertion is false

Not implemented

context, createTask, profile, profileEnd, timeStamp.

Tests: node-api node:console: 20 pass, 1 fail, 0 error, 1 skipped. Failing: test-console-issue-43095.js.

Was this page helpful?