Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Node.js · Const

console

Node.js's global console is a built-in debugging logger. It provides familiar logging methods and is preconfigured to write normal output and errors to the process standard streams.

How it works

The global console is a ready-to-use Console instance. Its methods provide formatted diagnostic output, with ordinary messages directed to process.stdout and warnings or errors directed to process.stderr; a separate Console instance can target custom writable streams.

Syntax

console
console.log(...args)
console.error(...args)
console.warn(...args)

Returns

A global console instance; its logging methods write diagnostic output to configured Node.js streams.

Key points

  • Node.js provides a built-in debugging console with browser-like console operations.
  • The API exposes both the Console class and a preconfigured global console instance.
  • The class includes common logging methods for normal, error, and warning output.
  • Console methods can target writable Node.js streams, enabling configurable output destinations.
  • The standard global instance is configured around the process's standard output channels.

Common mistakes

  • The global instance is already available, so importing the module is unnecessary when using the standard console.
  • A custom logger requires writable output streams; do not assume it uses the process standard streams.

Example: Write diagnostic output

console.log('Application started');
console.error('Example error output');

Uses the built-in global console to write normal output and errors to Node.js's standard output and error streams.

When to use it

Application logging

Emit diagnostic messages during application execution.

Error reporting

Report failures or abnormal conditions separately from ordinary output.

Custom stream logging

Create a logger directed to selected writable streams.

Interview questions

QWhat is the difference between the global console and the Console class?

console is the global instance exported by the node:console module. It is configured to write to process.stdout and process.stderr, while the Console class lets applications create loggers with other writable streams.

Follow-up: How would you route logs to a file? Construct Console with writable streams connected to the desired file destinations.

QHow do you use Node.js's built-in console?

Use the global object directly, for example console.log() for ordinary output and console.error() for error output. It is available without importing node:console.

Follow-up: When would importing the module still be useful? Import it when creating a separately configured Console instance or when explicit module dependencies improve clarity.

QWhat is the purpose of the Node.js console API?

The module provides a debugging console similar to the console mechanism in web browsers. Its methods can write to Node.js streams, making it suitable for straightforward diagnostic logging.

Follow-up: What architectural concern follows from configurable streams? Choose stream destinations deliberately so diagnostics can be separated, captured, or redirected by the surrounding application.

  • node:console
  • Console
  • console.log()
  • console.error()
  • console.warn()
  • process.stdout
  • process.stderr

Source: Console. Checked 2026-10-15.