Application logging
Emit diagnostic messages during application execution.
Node.js · Const
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.
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.
console
console.log(...args)
console.error(...args)
console.warn(...args)A global console instance; its logging methods write diagnostic output to configured Node.js streams.
Console class and a preconfigured global console instance.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.
Emit diagnostic messages during application execution.
Report failures or abnormal conditions separately from ordinary output.
Create a logger directed to selected writable streams.
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.
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.
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:consoleConsoleconsole.log()console.error()console.warn()process.stdoutprocess.stderr