Console | Node.js v25.9.0 Documentation Skip to content Node.js About this documentation Usage and example Assertion testing Asynchronous context tracking Async hooks Buffer C++ addons C/C++ addons with Node-API C++ embedder API Child processes Cluster Command-line options Console Crypto Debugger Deprecated APIs Diagnostics Channel DNS Domain Environment Variables Errors Events File system Globals HTTP HTTP/2 HTTPS Inspector Internationalization Modules: CommonJS modules Modules: ECMAScript modules Modules: node:module API Modules: Packages Modules: TypeScript Net Iterable Streams API OS Path Performance hooks Permissions Process Punycode Query strings Readline REPL Report Single executable applications SQLite Stream String decoder Test runner Timers TLS/SSL Trace events TTY UDP/datagram URL Utilities V8 VM WASI Web Crypto API Web Streams API Worker threads Zlib Zlib Iterable Compression Code repository and issue tracker Table of contents Console Class: Console new Console(stdout[, stderr][, ignoreErrors]) new Console(options) console.assert(value[, ...message]) console.clear() console.count([label]) console.countReset([label]) console.debug(data[, ...args]) console.dir(obj[, options]) console.dirxml(...data) console.error([data][, ...args]) console.group([...label]) console.groupCollapsed() console.groupEnd() console.info([data][, ...args]) console.log([data][, ...args]) console.table(tabularData[, properties]) console.time([label]) console.timeEnd([label]) console.timeLog([label][, ...data]) console.trace([message][, ...args]) console.warn([data][, ...args]) Inspector only methods console.profile([label]) console.profileEnd([label]) console.timeStamp([label]) Console Source Code: lib/console.js Stability: 2 - Stable The node:console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. The module exports two specific components: Console class with methods such as console.log() console.error() , and console.warn() that can be used to write to any Node.js stream. A global console instance configured to write to process.stdout and process.stderr . The global console can be used without calling require('node:console') Warning : The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. Programs that desire to depend on the synchronous / asynchronous behavior of the console functions should first figure out the nature of console's backing stream. This is because the stream is dependent on the underlying platform and standard stream configuration of the current process. See the note on process I/O for more information. Example using the global console console log 'hello world' // Prints: hello world, to stdout console log 'hello %s' 'world' // Prints: hello world, to stdout console error new Error 'Whoops, something bad happened' )) // Prints error message and stack trace to stderr: // Error: Whoops, something bad happened // at [eval]:5:15 // at Script.runInThisContext (node:vm:132:18) // at Object.runInThisContext (node:vm:309:38) // at node:internal/process/execution:77:19 // at [eval]-wrapper:6:22 // at evalScript (node:internal/process/execution:76:60) // at node:internal/main/eval_string:23:3 const name 'Will Robinson' console warn `Danger ${ name ! Danger!` // Prints: Danger Will Robinson! Danger!, to stderr Example using the Console class: const out getStreamSomehow () const err getStreamSomehow () const myConsole new console Console (out err) myConsole log 'hello world' // Prints: hello world, to out myConsole log 'hello %s' 'world' // Prints: hello world, to out myConsole error new Error 'Whoops, something bad happened' )) // Prints: [Error: Whoops, something bad happened], to err const name 'Will Robinson' myConsole warn `Danger ${ name ! Danger!` // Prints: Danger Will Robinson! Danger!, to err Class: Console History Version Changes v8.0.0 Errors that occur while writing to the underlying streams will now be ignored by default. The Console class can be used to create a simple logger with configurable output streams and can be accessed using either require('node:console').Console or console.Console (or their destructured counterparts): import Console from 'node:console' const Console require 'node:console' const Console console new Console(stdout[, stderr][, ignoreErrors]) new Console(options) History Version Changes v24.10.0 The inspectOptions option can be a Map from stream to options. v14.2.0, v12.17.0 The groupIndentation option was introduced. v11.7.0 The inspectOptions option is introduced. v10.0.0 The Console constructor now supports an options argument, and the colorMode option was introduced. v8.0.0 The ignoreErrors option was introduced. options