Open In App
Related Articles

Node.js Console Complete Reference

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Node.js console module is a global object that provides a simple debugging console similar to JavaScript to display different levels of the message. It is provided by web browsers.

Example:

Javascript

<script>
    // Node.js program to demonstrate the
    // console.trace() method
      
    // Accessing console module
    const console = require('console');
      
    // Calling console.trace() method
    console.trace("stack teace sample");
      
    console.trace(
        "stack trace sample with args: %d", 39);
</script>

                    

Output:

Trace: stack teace sample
at Object. (C:\nodejs\g\console\console_trace.js:4:9)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Trace: stack trace sample with args: 39
at Object. (C:\nodejs\g\console\console_trace.js:5:9)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
 

The complete list of NodeJS Console are listed below:

Node.js Console

Description

Node.js console.assert() MethodIt checks whether the value is true or not and print an error message, if provided and failed to assert the value. 
Node js console.clear() MethodThe console.clear() will work differently across different operating systems and terminal types.
Node.js console.count() MethodThis  is used to count label passed to it as a parameter, by maintaining an internal counter for that specific label.
Node.js console.countReset() MethodThis is used to reset the count for the specific label passed to it as a parameter.
Node.js console.debug() MethodThis is used to print messages to stdout in a newline. Similar to console.log() method.
Node.js console.dir() MethodThis is used to get the list of object properties of a specified object.
Node.js console.error() Function This is used to display an error messages on the console. It prints to stderr with newline.
Node.js console.info() MethodThis is used to print messages to stdout in a newline. It is similar to console.log() method.
Node.js console.timeLog() MethodThis is used to display the time for each execution. This function is proved to be effective when used in a loop.
Node.js console.time() Method It is used to starts a timer that is used to compute the time taken by a piece of code or function. 
Node.js console.table() MethodIt is used to print the table constructed from it’s parameters into the console.
Node.js new Console() MethodThis is inbuilt application programming interface of the ‘console’ module which creates a new Console with single or multiple writable streams
Node.js console.profile() MethodThe console.profile() (Added in v8.0.0) method is an inbuilt application programming interface of the ‘console‘ module which doesn’t display anything unless used in the inspector.
Node.js console.profileEnd() MethodThe console.profileEnd() (Added in v8.0.0) method is an inbuilt application programming interface of the ‘console’ module which does not display anything unless used in the inspector.
Node.js console.timeStamp() MethodThis is an inbuilt application programming interface of the ‘console‘ module which does not display anything unless used in the inspector.
Node.js console.timeEnd() Method This method stops a timer that was previously started by using console.time() method and display the result using stdout.
Node.js console.trace() MethodThis  is used to print stack trace messages to stderr in a newline. Similar to console.error() method.
Node.js console.warn() FunctionThis is used to display the warning messages on the console. It prints to stderr with newline.


Last Updated : 05 Dec, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads