Node.js - Console Module
NodeJS Console is a global object that enables a convenient debugging console to display different message levels. This debugging console is identical to JavaScript console mechanism provided by web-browsers. The console module has two specific components, which are described as below −
Console class − Methods like console.log(), console.warn(), and console.error are present in the console class. Any Node.js stream can be writtenusing these methods.
Global console − The global console instance is configured to write process.stdout and process.stderr(this property returns a stream connected to stdout). It is possible to operatewithout using the require("node:console") function.
List of Methods
Following are the list of methods available in the console class −
| Sr.No | Module & Description |
|---|---|
| 1 |
Used to verify the invariants. |
| 2 |
Used to clear the stdout (standard output). |
| 3 |
Used to get the count of the number of times the function has been called with a specific input value. |
| 4 |
Used to reset the count for the specific input value which is passed as a label. |
| 5 |
Used to print information to stdout in a new line |
| 6 |
Used to get the properties of a particular object. |
| 7 |
Used to call the console.log() method at the time of execution by passing the arguments received. |
| 8 |
Used to display the error messages on the console. |
| 9 |
Used to get the passed information in the method as a grouped format. |
| 10 |
Used to collapse the previously created group by console.group(). |
| 11 |
Used to end the group; which was created with console.group() and console.groupCollapsed() methods. |
| 12 |
Used to print information to stdout in a new line. |
| 13 |
Used to print information to stdout in a new line. |
| 14 |
Used to create a table in the console. |
| 15 |
Used to start a timer that we can use to track the time taken by an operation or any function. |
| 16 |
Used to stop the timer which was previously started by console.time() method. |
| 17 |
Used to print the elapsed time for a timer that was previously started by calling console.time(). |
| 18 |
Used to print the stack 'Trace' to the current position of the code followed by the message and substitution values on stderr in a new line. |
| 19 |
Used to print the warning messages to the console. |
| 20 |
creates a new Console with one or two instances of writable streams, namely stdout and stderr. |
Inspector only methods
The following methods doesn't display anything unless used in the browser inspector.
| Sr.No | Module & Description |
|---|---|
| 1 |
Used to start a JavaScript CPU profile. |
| 2 |
Used to stop the JavaScript CPU profiling session of the profile, which has been called previously. |
| 3 |
Used to add an event with or without the label to the timeline panel of the inspector tab. |