Skip to content
Related Articles

Related Articles

Improve Article

Node.js console.timeStamp() Method

  • Last Updated : 06 Sep, 2020

The console module provides a simple debugging console that is provided by web browsers which export two specific components:

  • A Console class that can be used to write to any Node.js stream. Example: console.log(), console.error(), etc.
  • A global console that can be used without importing console. Example: process.stdout, process.stderr, etc.

The console.timeStamp() (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. This method adds an event with the label ‘label‘ to the Timeline panel of the inspector.

Note: The global console methods are neither consistently synchronous nor consistently asynchronous.

Syntax:

console.timeStamp([label])

Parameters: This function accepts a single parameter as mentioned above and described below:



  • label <string>: It accepts the label name that is further to be used in the inspector.

Return Value: It doesn’t print anything in console instead, prints timestamp at the call in Inspector.

The Below examples illustrate the use of console.timeStamp() method in Node.js.

Example 1:   Filename: index.js




// Node.js program to demonstrate the 
// console.timeStamp() Method
  
// Starting newProfile() console profile
console.profile("Hello()");
  
// Printing timestamp
console.timeStamp("Hello()");
  
// Finishing profile
console.profileEnd("Hello()");


Run index.js file using the following command:

node index.js

Output in Console:

*Doesn’t print anything in Console…

Output in Inspector(edge):



Example 2:   Filename: index.js




// Node.js program to demonstrate the 
// console.timeStamp() Method
  
// Starting Hello() console profile
console.profile("Hello()");
  
// Printing timeStamp
console.timeStamp("Hello()");
  
// Performing some action
for(var i=0; i<1; i++) {
  console.log("doing some task...");
}
  
// Finishing profile
console.profileEnd("Hello()");
  
// Printing timeStamp again
console.timeStamp("Hello()");


Run index.js file using the following command:

node index.js

Output in Console:

Doing some task…

Output in Inspector (edge):

Reference: https://nodejs.org/api/console.html#console_console_timestamp_label




My Personal Notes arrow_drop_up
Recommended Articles
Page :