Skip to content
Related Articles
Open in App
Not now

Related Articles

Node.js Console Complete Reference

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 05 Dec, 2022
Improve Article
Save Article

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() Method It 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() Method The console.clear() will work differently across different operating systems and terminal types.
Node.js console.count() Method This  is used to count label passed to it as a parameter, by maintaining an internal counter for that specific label.
Node.js console.countReset() Method This is used to reset the count for the specific label passed to it as a parameter.
Node.js console.debug() Method This is used to print messages to stdout in a newline. Similar to console.log() method.
Node.js console.dir() Method This 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() Method This is used to print messages to stdout in a newline. It is similar to console.log() method.
Node.js console.timeLog() Method This 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() Method It is used to print the table constructed from it’s parameters into the console.
Node.js new Console() Method This is inbuilt application programming interface of the ‘console’ module which creates a new Console with single or multiple writable streams
Node.js console.profile() Method The 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() Method The 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() Method This 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() Method This  is used to print stack trace messages to stderr in a newline. Similar to console.error() method.
Node.js console.warn() Function This is used to display the warning messages on the console. It prints to stderr with newline.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!