Node.js console.debug() Method

The console.debug() method is an inbuilt application programming interface of the console module which is used to print messages to stdout in a newline. Similar to console.log() method.

Syntax:

console.debug(data, args);

Parameters: This method has two parameters as mentioned above and described below:

  1. data: This parameter specifies the data to be printed.
  2. args: It is optional parameter that specifies parameters to be passed as substitution values in message passed to data. All passed args are sent to util.format().

Return Value: This method doesn’t return anything but print the formatted message to stdout in a newline.

Below examples illustrate the use of console.debug() method in Node.js:



Example 1: Filename: app.js

filter_none

edit
close

play_arrow

link
brightness_4
code

// Accessing console module
const console = require('console');
  
// Calling console.debug() 
console.debug("This is a sample debug message!");
console.debug("Sample debug message with args: %d", 39);

chevron_right


Run the app.js file using the following command:

node app.js

Output:

This is a sample debug message!
Sample debug message with args: 39

Example 2: Filename: app.js

filter_none

edit
close

play_arrow

link
brightness_4
code

// Accessing console module
const console = require('console');
  
// Calling console.debug()
console.debug("This is a %s"
    " sample debug message!");
console.debug("Sample debug message"
    + " with args: %d", 34);
console.debug("Debug message: Warning "
    + "at function %s: line number %d ",
    "ff()",96)
  
var isDebugMode = true;
console.custom_debug = function(message) { 
  if (isDebugMode) {
    console.log(message);
  }
}
  
console.custom_debug("Custom debug message");

chevron_right


Run the app.js file using the following command:

node app.js

Output:

This is a  sample debug message!
Sample debug message with args: 34
Debug message: Warning at function ff(): line number 96
Custom debug message

Note: The above program will compile and run by using the node filename.js command.

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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.