You are here: Home / Topics / Node.js – Console

Node.js – Console

Filed under: NodeJs on 2024-02-22 20:42:55

Node.js console is a global object and is used to print different levels of messages to stdout and stderr. There are built-in methods to be used for printing informational, warning, and error messages. It is used in synchronous way when the destination is a file or a terminal and in asynchronous way when the destination is a pipe. 

Console Methods: 

Following is a list of methods available with the console global object.

Sr.No.Method & Description
1console.log([data][, ...])
Prints to stdout with newline. This function can take multiple
arguments in a printf()-like way
2console.info([data][, ...])
Prints to stdout with newline. This function can take multiple
arguments in a printf()-like way.
3console.error([data][, ...])
Prints to stderr with newline. This function can take multiple
arguments in a printf()-like way.
4console.warn([data][, ...]) Prints to stderr with newline. This function can take multiple arguments in a printf()-like way
5console.dir(obj[, options])
Uses util.inspect on obj and prints resulting string to stdout.
6console.time(label)
Mark a time.
7console.timeEnd(label)
Finish timer, record output.
8console.trace(message[, ...])
Print to stderr 'Trace :', followed by the formatted message and
stack trace to the current position.
9console.assert(value[, message][, ...])
Similar to assert.ok(), but the error message is formatted as
util.format(message...).
  
About Author:
T
Team MCQ Buddy     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.